• Language choices.
    5 replies, posted
Hey, I am making website for college project. And I want to make it in like 12 languages. Is there a way to make like: <li><a href="index.htm>#Home</a></li>, and so there are seperate language files, like Russian.php or xml or something and in corner of page there is a drop down box where you select language, and depending on drop down menu selection it loads the file with those pre-made texts. So #Home replaces with the specific language word. Help please? thanks.
Localization is what you want to read up on.
[QUOTE=arleitiss;32734197]Hey, I am making website for college project. And I want to make it in like 12 languages. Is there a way to make like: <li><a href="index.htm>#Home</a></li>, and so there are seperate language files, like Russian.php or xml or something and in corner of page there is a drop down box where you select language, and depending on drop down menu selection it loads the file with those pre-made texts. So #Home replaces with the specific language word. Help please? thanks.[/QUOTE] No no no. If you want a quick way to implement this without too much trouble, do this: Create a PHP file for each language (except the original language), in this format: [php] return array( 'Hello' => 'Olá', 'Thank you for using Pants(tm)' => 'Obrigado por usar Calças(tm)' ); [/php] As you can see each English sentence is mapped to its translation. Repeat for every word or sentence you want to translate, for every language. Then you have your logic that takes care of selecting a language, and do something like: [php]$translated = require 'path/to/files/LANGUAGE.php';[/php] Now your $translated variable has the array of translations. Then create a function more or less like this: [php] function _($sentence) { global $translated; return isset($translated[$sentence]) ? $translated[$sentence] : $sentence; } [/php] And wherever you want to have a word or sentence translated: [php] <h1><?php echo _('Welcome to My Website') ?></h1> [/php] Sentences are automatically replaced by their translated versions only IF they exist, otherwise the original string that you passed to the _ function is returned. This lets you gradually translate everything while still having a working prototype. You can even modify the return for untranslated strings so they're somehow highlighted (IIRC, Microsoft mangles strings that aren't properly localized, so they come out looking like a bunch of symbols mixed with the original sentence to draw the developer's attention). This does [b]not[/b] fit a large project, but it's more than enough for a school assignment. Let me know if you need any more help.
How would you go about doing it for a larger project if you don't mind me asking? I only ask because we're attempting a fairly large project and localisation will be really important.
[QUOTE=Jelly;32734561]How would you go about doing it for a larger project if you don't mind me asking? I only ask because we're attempting a fairly large project and localisation will be really important.[/QUOTE] punbb/fluxbb does this pretty well for an example if you want to look at that
[QUOTE=Kwaq;32734725]punbb/fluxbb does this pretty well for an example if you want to look at that[/QUOTE] Not really, it's one of the things I'm helping with for FluxBB 2.0. It works, but the extra overhead is pretty high, there's very little consistency between translation, implementation, and between the various translation files. When possible, the [b]gettext[/b] extension is a good choice, array-based implementations (like my example above, or Flux) are also solid (but my example isn't sturdy enough for a large project), and then there's PHP implementations of gettext, which I wouldn't recommend due to their overhead. I've got a pretty bad headache, so excuse me if my wording isn't too clear.
Sorry, you need to Log In to post a reply to this thread.