Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,149,979 members, 7,806,859 topics. Date: Wednesday, 24 April 2024 at 04:43 AM

Language And Url In Website - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Language And Url In Website (1084 Views)

RTMP URL In Videoview / Nairaland Programmers That Share Language And City In Common / Help: C Language And MPI ? (urgent Plz) (2) (3) (4)

(1) (Reply) (Go Down)

Language And Url In Website by jaiylsbird: 11:37pm On Jun 17, 2013
I have a website that iam working for atm, at first it was only in english, but now the client said he wants to add a few more languages, french, italian and spanish, he send me this website as reference http://www.travideos.com/, notice how if you change the language it adds it to the url, example: http://fr.travideos.com/, i have no idea how to do that, but of course i cant say that to the client, jeje, can someone here help me with this.
Re: Language And Url In Website by Javanian: 11:41pm On Jun 17, 2013
which is your problem.

1. creating a sub domain i.e. fr.yourdomain.com

2. having your site in other languages.

These are two different problems

1 Like

Re: Language And Url In Website by spikesC(m): 11:49pm On Jun 17, 2013
Oh dude, you're just fcked embarassed

You have 2 choices
1. Use the easy method, google translate

2. The "you're fcked method", build an internal translation function from scratch and run ALL your application ouput strings through it. Therefore you'll have to do a thorough manual search and replace wink

When you chose your method, tell me, i'll gladly help
Re: Language And Url In Website by tundebabzy: 11:27am On Jun 18, 2013
spikes C: Oh dude, you're just fcked embarassed

You have 2 choices
1. Use the easy method, google translate

2. The "you're fcked method", build an internal translation function from scratch and run ALL your application ouput strings through it. Therefore you'll have to do a thorough manual search and replace wink

When you chose your method, tell me, i'll gladly help

Google translate is not free so it could cause friction with your client because they charge according to use.

Manually translating your site then copy pasting into your html is just not right. Apart from the sheer work involved, anytime there is even just the tiniest change, you would have to do the whole process all over again leaving open doors for bugs.

Dude, the best option is to find a decent framework in your favorite programming language that has built in support for internalization and use it to rebuild your site.
Re: Language And Url In Website by spikesC(m): 5:55pm On Jun 18, 2013
tundebabzy:

Google translate is not free so it could cause friction with your client because they charge according to use.

Manually translating your site then copy pasting into your html is just not right. Apart from the sheer work involved, anytime there is even just the tiniest change, you would have to do the whole process all over again leaving open doors for bugs.

Dude, the best option is to find a decent framework in your favorite programming language that has built in support for internalization and use it to rebuild your site.

I didn't mean html, i meant text strings. Even the frameworks use it, you still have to pass in the text strings into the function and write your own language files. No one can ever do that for you
Re: Language And Url In Website by sarutobi: 9:47am On Jun 19, 2013
spikes C: Oh dude, you're just fcked embarassed

You have 2 choices
1. Use the easy method, google translate

2. The "you're fcked method", build an internal translation function from scratch and run ALL your application ouput strings through it. Therefore you'll have to do a thorough manual search and replace wink

When you chose your method, tell me, i'll gladly help

No 2 is the way to go. and dont worry u are not bleeped grin . You still employ the same template as with ur current site. All u need do is have files that maps words to thier corresponding translations in diff languages. This can be done with xml, json or YAML. eg for french you have translations.fr, for italian you have translations.it etc

Then in ur template, u have string placeholders that loads this translations when the script encouters them. U will want to load all the data in an associated array(PHP), turples(python) or my personal favorite Maps(java) at runtime so that u dont open a file every time you need to subtitute a placeholder.

Your program will have to determine the location of the visitor through IP address and redirect accordingly. There are many projects that can help you with geolocation. In this regard, u also have 2 options as pointed out by javanian, u could create subdomains for each country eg fr.[youtsitedomain].com and have your script do the redirect based on ip address. or you could create a URL parameter like www.[youtsitedomain].com?lang=fr. the subdomain is cleaner though, but it is more work.

Most web frameworks come with this so just go for one of them.


@Spikes C
"Therefore you'll have to do a thorough manual search and replace" - manual search and replace mite be slow sir. Instead, each word should be represented by a hash key in a collection like a hashmap for fast lookup which then points to that word's tranlations. This way, words like ("is", "they", "we"wink that are common will only be replaced once cos all of them will produce the same hash value. manual search and replace will replace each time it sees a word, even if that word oocurs millions of times.
Re: Language And Url In Website by spikesC(m): 4:36pm On Jun 19, 2013
What you fail to understand is that string of words do not make meaning when translated, that is why google translate still have errors.

Do not use hash for the keys because you need a fail safe method, if a hash does not exist in a language file, what happens. To explain more, i'll post the method i use when i get to my pc.

Secondly, i think you misunderstood me, i didn't say he should do a search and replace and have multiple files, i meant he should do a search and replace on the template and run the strings through the function.

E.g replace 'home' with lang('home')


Give me a few hours, let me get to my pc wink
Re: Language And Url In Website by spikesC(m): 6:49pm On Jun 19, 2013
This is the language file for english. named en.php
Read the comments to understand the benefits of each part


<?php
function lang($phrase){

//static : so that the variable is not declared on every function run
//I use pure arrays so there's no need for preprocessing like sarutobi suggested
static $strings = array(

//the keys are all small letters not capitals, very very important
'home' => 'Home',
'account' => 'Account',
'join' => 'Join',
'login' => 'Login',
'proceed' => 'Proceed',
'verify' => 'Verify',
'post' => 'Post',
'ad blocks' => 'Ad Blocks',
'footer left' => 'Footer left',
'footer right' => 'Footer right',
'footer bottom left' => 'Footer bottom left',
'footer bottom right' => 'Footer bottom right',
'your e-currency account number' => 'Your e-currency account number',
'your e-currency account name' => 'Your e-currency account name',
);

//convert the phrase to small letters so as to match with the keys
$phrase = strtolower(trim($phrase));

//if the phrase exists, display the translation, else display the phrase itself
//This is the fail safe part, if the phrase translation does not exist, the phrase itself should be displayed.
//If you use hash keys, the hash would be displayed grin

if(array_key_exists($phrase,$strings)){
return $strings[$phrase];
}else{
return $phrase;
}
}
Re: Language And Url In Website by spikesC(m): 6:52pm On Jun 19, 2013
This is my config file, it gets included on every page
ROOT is a constant i declared myself. I always have problem with include files embarassed


//set and import language files with its function
if(!isset($_SESSION['LANG'])){$_SESSION['LANG'] = 'en';}

require_once ROOT . "language/$_SESSION[LANG].php";
Re: Language And Url In Website by sarutobi: 7:13pm On Jun 19, 2013
spikes C: This is the language file for english. named en.php
Read the comments to understand the benefits of each part


<?php
function lang($phrase){

//static : so that the variable is not declared on every function run
//I use pure arrays so there's no need for preprocessing like sarutobi suggested
static $strings = array(

//the keys are all small letters not capitals, very very important
'home' => 'Home',
'account' => 'Account',
'join' => 'Join',
'login' => 'Login',
'proceed' => 'Proceed',
'verify' => 'Verify',
'post' => 'Post',
'ad blocks' => 'Ad Blocks',
'footer left' => 'Footer left',
'footer right' => 'Footer right',
'footer bottom left' => 'Footer bottom left',
'footer bottom right' => 'Footer bottom right',
'your e-currency account number' => 'Your e-currency account number',
'your e-currency account name' => 'Your e-currency account name',
);

//convert the phrase to small letters so as to match with the keys
$phrase = strtolower(trim($phrase));

//if the phrase exists, display the translation, else display the phrase itself
//This is the fail safe part, if the phrase translation does not exist, the phrase itself should be displayed.
//If you use hash keys, the hash would be displayed grin

if(array_key_exists($phrase,$strings)){
return $strings[$phrase];
}else{
return $phrase;
}
}

This is the fail safe part, if the phrase translation does not exist, the phrase itself should be displayed.
//If you use hash keys, the hash would be displayed
- it won't, it won't, it won't grin grin tongue cool cheesy wink but i dont want to argue grin
@OP: there is ur solution
@spike c: good one.
Re: Language And Url In Website by spikesC(m): 7:33pm On Jun 19, 2013
sarutobi:

This is the fail safe part, if the phrase translation does not exist, the phrase itself should be displayed.
//If you use hash keys, the hash would be displayed
- it won't, it won't, it won't grin grin tongue cool cheesy wink but i dont want to argue grin
@OP: there is ur solution
@spike c: good one.

It depends on your algorithm, pls tell us grin
No argument but debate, we gotta learn new things everyday na cool

(1) (Reply)

Which Language Should I Use To Create Smartphones App. / Mathematics Or Computer Sc. / C# Asp.net Or Php

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 34
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.