Welcome to our forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Forum Statistics

  • Forum Members:
  • Total Threads:
  • Total Posts: 7
There are 1 users currently browsing forums.
HTML/CSS Coding The basis of the World Wide Web, HTML, XHTML, and CSS make our forum possible, so it must be important right? Ask questions and receive help with these markups here.

Reply
  #1  
Old 11-29-2009
cancer10's Avatar
A "Mature" Pre-Teenager!
 
Join Date: Jun 2005
Location: India
Age: 27
Posts: 515
Rep Power: 5
cancer10 is on a distinguished road
Question Multi-lingual site

Hi

I want my site to be multi-lingual (chinese, french etc). I was wondering how do I proceed.


I have seen many sites that have multiple languages. Just wondering whats the best way to do it?


Any help will be highly appreciated.


Many thanks
Reply With Quote
  #2  
Old 11-29-2009
vento's Avatar
Sexy monkey
 
Join Date: May 2009
Location: Lithuania
Age: 16
Posts: 185
Rep Power: 1
vento is on a distinguished road
Re: Multi-lingual site

I'm not sure if it's the best way, but if you're using PHP then you can take a look at define:

Code:
<?php
define( 'HOME', 'Home' );
define( 'PRODUCTS', 'Products' );
define( 'COPYRIGHTS', 'Copyrighted by God 1814-2010' );
?>
I think it's a nice way to define all language specific stuff, isn't it? If you want to translate you're website to another language, all you have to do is to make a copy of one of the existing language files and simply translate all the definitions.

If you think I suggest adding this code to a template or somewhere else by another code - you're wrong. You should make another file like lang_CH.php, lang_EN.php and then include one of them using a language switcher (a script that decided which language is needed).

Use of definitions:
Code:
<!-- lots of code here -->
<a href='index.php' target='_self'><?=HOME ?></a>
<!-- more code here -->
or you could use constant to make sure it returns the right value in any case:
Code:
<!-- lots of code here -->
<a href='index.php' target='_self'><?=constant('HOME'); ?></a>
<!-- more code here -->
in some cases you may want to check if the definitions is set (probably not in a language case, but anyway, it's worth knowing possibilities) you could use defined():
Code:
<!-- lots of code here -->
<?php
if( defined('WARNING') )
    echo constant('WARNING').'<br />';
?>
 <a href='index.php' target='_self'><?=constant('HOME'); ?></a>
 <!-- more code here -->
It could be also done by using MySQL database, but I thing that definitions are faster.
__________________

How to set up portable C++ IDE (Dev-C++)

Writing in C or C++ is like running a chain saw with all the safety guards removed," — Bob Gray.

Last edited by vento; 11-29-2009 at 01:57 AM. Reason: Grammar mistake
Reply With Quote
  #3  
Old 11-29-2009
cancer10's Avatar
A "Mature" Pre-Teenager!
 
Join Date: Jun 2005
Location: India
Age: 27
Posts: 515
Rep Power: 5
cancer10 is on a distinguished road
Re: Multi-lingual site

Hi

Thanks a ton for your reply.



In your code, I do not see how will it change the content of the site to other language (say french). Only it does is include the constant to the page.


Pls elaborate.




Thanks again
Reply With Quote
  #4  
Old 11-30-2009
vento's Avatar
Sexy monkey
 
Join Date: May 2009
Location: Lithuania
Age: 16
Posts: 185
Rep Power: 1
vento is on a distinguished road
Re: Multi-lingual site

You don't have to worry about that. If you have used C++, it's easier to understand how it works, but I guess you haven't.

Using define() you just say the server that you want to replace each HOME, WARNING, COPYRIGHT, etc into whatever you define them to. constant function is not necessary, but using it you will always be 100% sure that it's going to print value of defined word. I'm not sure what constant returns if it's undefined, you should check it. I'm not sure how it is done exactly in PHP, but in C++ it works like this:

you write your code, let's say like this:
Code:
#include <iostream>

#define HELLO "Hello World!\n"

int main()
{
    std::cout << HELLO;
    return 0;
}
And when you run the compiler, it goes through the code line by line doing pre-compile tasks (it's those lines with # at the beginning) first. So it find that HELLO is defined as "Hello World!\n" (every symbol is marked as definition, even quotes). So now wherever it finds HELLO, it gonna replace it with "Hello World!\n". So before running the actual compilation, the file copy will look like this:

Code:
//lots of lined included from <iostream>

int mai()
{
    std::cout << "Hello World!\n";
    return 0;
}
In PHP it works similar way. Every definitions is held in a special variable and if the compiler finds exactly the same (case-sensitive) characters sequence, it gonna be replaced by whatever you define.

P.S. As I said, i'm not 100% sure how PHP does it exactly, but it has to be included before the code where you use those defined words. In other words, the server must first read your definitions and only then it can replace it. You can't include lang.php at the end of file, because the server is not going to understand what you actually want by typing HOME because it hasn't read it yet.

P.S.S. Definitions can be both lower and upper case, but it's a coding style that it's usually upper case only.

Hopefully you understood.
__________________

How to set up portable C++ IDE (Dev-C++)

Writing in C or C++ is like running a chain saw with all the safety guards removed," — Bob Gray.
Reply With Quote
  #5  
Old 11-30-2009
Moderator
 
Join Date: Dec 2005
Posts: 1,862
Rep Power: 6
Umang is on a distinguished road
Re: Multi-lingual site

Hi,
I haven't gone through the whole thread, but as far as I know, the most common thing to do is to make multiple sub-domains. (e.g en.wikipedia.org for English, fr.wikipedia.org for French).
Check this: Wikipedia

Hope this helps
Reply With Quote
  #6  
Old 11-30-2009
vento's Avatar
Sexy monkey
 
Join Date: May 2009
Location: Lithuania
Age: 16
Posts: 185
Rep Power: 1
vento is on a distinguished road
Re: Multi-lingual site

Well, yes, for the content, it's always simplier to make different files like article_EN.php, article_PL.php and so on. It's probably because of the amount of data. But some systems still use define for menu, status, copyrights and so on... It's up to you what way fits your needs the best.

Another thing about wiki. They do so because they have different articles in each language. Those wikis are not connected to each other. Well, the only connection is a link to other language on the left side of site.
Reply With Quote
  #7  
Old 12-01-2009
Moderator
 
Join Date: Dec 2005
Posts: 1,862
Rep Power: 6
Umang is on a distinguished road
Re: Multi-lingual site

Ah, yes. You have a point about the wiki...
Reply With Quote


Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Idea for Tutorial Site haydenbech General Web Programming 6 01-30-2007 11:06 AM
PHP site Mirroring cpf PHP Scripting 7 01-12-2007 08:04 PM
Please Review my Site klair Site Reviews & Site Management 10 09-04-2006 12:10 PM
I have over hauled my site Mauiman Site Reviews & Site Management 13 03-26-2006 03:22 PM
Design an EyeCatching Site wizard Articles, Tutorials, and Guides 7 03-08-2006 07:09 AM