What is a better way to create multi-language website?

Discussion in 'Web Design and Development' started by stndn, May 7, 2007.

  1. stndn macrumors member

    Oct 22, 2006

    We are trying to make multi-language website.
    Our website itself is based on php/mysql, plus some other things here and there.

    Now, we have talked about different ways of accomplishing it and it came down to two options:

    1. Use templates.
    Basically what this means is that we will create two identical templates, with different texts used depending on the language the user is currently looking at. When we load our pages, we will have to check the current language and load the templates accordingly.
    This is similar to what apache's manual has.

    2. Use variables.
    Similar to option 1, we would define a list of variables which contain the texts we want to use. The variable will then be placed in a single template file. When we load the page, we would read the contents of the variable and then it will be replacing the variables in our template.
    This is similar to what phpmyadmin has.

    The question is, which do you think is a better approach?

    With option 1, we would be less confused when defining the template, as we can see it right away when we create the templates. However, changing one language's template will require us to remember changing the template for other languages, and this is more likely to be missed.

    With option 2, changing the template only needs to be done once. However, we need to be sure that our variables contain correct entries. Plus, when the variables grow in size (which is not unlikely), the maintenance may give us headache.

    So, which one should we use?
    Or, do you have other suggestions as to how to create multi-language website without having to recreate too much code?

    Thank you.
  2. jng macrumors 65816


    Apr 6, 2007
    How many languages?

    I would create a table just indexing the languages.

    And in your content tables, for example "Pages", I would have ID, Title, Content, and LangID.

    Have a drop down or links that let you select a language which either sets a cookie or session variable to be used by PHP.

    Then, pull the proper row depending on the langID into your templates.

    Others might have a better idea.
  3. stndn thread starter macrumors member

    Oct 22, 2006
    We're looking at at least 30 pages of layouts and two languages for now.

    Sorry I'm confused, but from what you're saying, are you implying that we store each translation text in the database, then read it accordingly and place it in place when we generate our page?

    Maybe this will give a better idea on our problem:

    Suppose we want to show this forum in both english and chinese version.
    The posts we made will be in whatever original language it was written.
    The presentation, however, will have different language.

    For example, english will have 'submit reply', while chinese will have 'hui da' as the text. Similarly other texts. But both languages will share the same logic and layout.

    Thank you.
  4. jng macrumors 65816


    Apr 6, 2007
    Oy Chinese. I think the system I outlined above would still work though. I imagine that your are not coding a forum but rather using software. Therefore you'd just need to apply your design.

    You'd use the database for content pages. For smaller things like the button you talked about you could store in a different table, but similar structure.
  5. stndn thread starter macrumors member

    Oct 22, 2006
    Yah, the page will not be a forum site.
    I'm just using this forum as example because that's the fastest I could think of.
    The choice of 'Chinese' language was also picked up as an example. However, that doesn't mean we won't be using Chinese somewhere down the road...

    Actually, when we began thinking about all this, we were trying to move away from storing the translation in database. Our thought was that if we put the translations in database, doesn't that mean we will have to do a lot of queries to get the translations?

    Or maybe we were just thinking too far away?

    Either way, I'll try bringing your suggestion up when we have our technical meeting and see what they say

  6. tschoftner macrumors member


    Apr 14, 2007
    joomla? typo3?

    Hi ya!
    Don't really know if that's an option for you, but you could use "joomla" (and get the multi language thing going with an extension called "joomfish") or you could use "typo3".
    I myself am using joomla. Once you get over the first hurdles of getting used to the whole system, it's (to my mind) quite easy to create.
    Best wishes,
  7. janey macrumors 603


    Dec 20, 2002
    sunny los angeles
    I second the joomfish idea.

    I'm not very fond of Joomla, but it sounds like it would work for your needs. Joomla's quirky and not as nice as Drupal in most ways (imo), but JoomFish is amazingly awesome if you have any i18n needs.

    I'm using it for a site in English+Korean, possibly other languages in the future.
  8. stndn thread starter macrumors member

    Oct 22, 2006
    Since we develop our own CMS in-house, I doubt we could use external program's extension.
    However, since I've never used Joomla or anything like that, I can't tell for sure.

    We will still look into it when we have time, though.
    For now, it looks like the languages will have to wait since a new batch of slavery is just around the corner -(

    Thank you all.
  9. stndn thread starter macrumors member

    Oct 22, 2006
    Just a little update.
    We have talked about this on our meeting, and the consensus was to use template files for each languages.

    So we will have:
    /home/web/en/template_1.html and /home/web/cn/template_1.html
    /home/web/en/template_2.html and /home/web/cn/template_2.html

    which will be loaded as needed.

    As for a few common navigational texts (which, unfortunately, gets defined and used outside where our template contents are), they will be loaded from another external file which contains only the variable-to-text translations, with different language in different files.

    Let's hope things are not that messy when we actually start the coding...

  10. jng macrumors 65816


    Apr 6, 2007
    So you're going with option #1? Rereading the original post, looks like you're making 2 different pages, not two different templates. If you are indeed making 2 different templates, it seems like it'll be inefficient to me. I don't know. But good luck.
  11. stndn thread starter macrumors member

    Oct 22, 2006
    Yes, we are leaning towards using option #1.

    Now that I re-read my own post, I can see where you think I'm loading different HTML pages rather than different templates. I guess it's a problem when we (our team) are confused regarding what we thought and what others suggest.

    My apology if it sounded like we're disregarding everyone's suggestions. We're not. We just had hard time digesting the words and suggestions.

    What we have in mind regarding our solution was something like this:

    # Start doing some php code here
    # ...

    # Check for language to include, be if from profile or cookie or session (most likely) or whatever

    # Read any additional language variables
    require_once '/home/web/' $languageID '/some_include_file.php';

    '/home/web/' $languageID '/template_1.html'

    # Do some other things

    require_once '/home/web/' $languageID '/template_2.html'

    # Do some more work and finish up
    So, in a sense, we only load the file depending on which language the user chose to use.

    We actually tried to think about the solution using database that everyone keeps suggesting (which, actually, was also the consensus on the other forum that I posted this question on). The problem was not that we don't want to follow that, but more so that we don't understand what everyone was talking about.

    Here's our thought regarding database:

    lang_id | lang_name
       1     |  en
       2     |  jp
    lang_id | page_id | page_filename
       1      | index    | /home/web/index.en.php
       2      | index    | /home/web/index.jp.php
       ... etc
    Isn't that essentially the same as our approach above, minus the need to query the page to read which template we wanted to load?

  12. msharp macrumors regular


    Jul 10, 2004
    Sorry guys, but just 30 pages and 2 languages, maybe just make 2 copies of your website is the simplest solution.

    In fact, there are many differences between languages. Simply replacing some text may not be the "perfect" solution, and in fact, it is low-efficient.

    Actually, if your website contains user interactive elements(forums, comments, etc) I strongly recommend building different websites respectively, as I do with my site, if you want to check it out.


    I designed this site, and there are 2 languages: en-us and simp chinese. I built the CMS(a very simple one actually) and made it a copy for simp chinese version.

    Most important, the site incorporated a blog-like article management system, powered by wordpress. So, posts in different languages should be visible to the correct people, and they make comments in corresponding language as well.

    To make it a better localization, making copies of your website seems to be the only way.

    Correct me if I'm misunderstanding the author's idea. ;)

Share This Page