SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2007
    Location
    Toronto
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    French Translation -- What is the easiest way?

    Hi everyone,

    I'm doing front end development for a very busy web development company here in Canada and we often do fairly large websites that require French Translation.

    Currently we are using a system that is very time consuming to implement the french content in the PHP pages.

    Here is an example of how we are including the content. Basically, there is a cookie variable stored that keeps the user's preference of French or English. The HTML with content looks something like this: (a rudimentary example)

    Code:
    <body>
    <h1><?=$page->getLabel('HOME_TITLE')?></h1>
    <p><?=$page->getLabel('HOME_CONTENT')?></p>
    <p><a href="about.php"><?=$page->getLabel('ABOUT_LINK_TEXT')?></a></p>
    </body>
    So, the PHP code that gets the "label", pulls the label text out of the database. The database has two entries for each label. One for each language.

    The reason this is time consuming is that, when I do the front end (HTML, CSS), I have to cut and paste every section of content and save them all into different entries in the DB.

    So since this would be very difficult and time consuming, when I cut the content out of the HTML, I bring a lot of the HTML with it. So the HTML ends up being inside the getLabel code, as opposed to what you see above. So it would look like this:

    Code:
    <body>
    <?=$page->getLabel('HOME_CONTENT')?>
    </body>
    So while example #2 is much easier to implement initially, I imagine it is much worse when doing updates to the HTML, since you have to actually go into the DB and edit the HTML right in there.

    So my question is, is there an easier way to do this without duplicating the entire website and doing updates in two different directories, or without doing updates to multiple entries in the DB, as shown above?

    Thanks,

    Louis

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are several posts on the forum with the same question. As I say in them my favourite for this is Zend_Translate with gettext.

    http://framework.zend.com/manual/en/zend.translate.html

  3. #3
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stadskle View Post
    As I say in them my favourite for this is Zend_Translate with gettext.

    http://framework.zend.com/manual/en/zend.translate.html
    That's really just a particular implementation. It doesn't solve Louistar's problem, as I understand it. Unless there's something more to Zend_Translate, that I don't know of?

    To address the question; I don't think there's an easy way, but you can at least do a couple of things. First, since you're going to write $page->getLabel() a lot, do yourself a favor and wrap it in a shorter function. If you use gettext, then it's done for you already, otherwise you can just invent your own. I use two underscores, eg. __("HOME_TITLE").

    Another thing you can so, is to use the English phrase as the label. So instead of __("HOME_TITLE"), you would write __("Frontpage"). Since you already have the content in English, it would be much faster to change it.

    Once you have this done, do write a script which logs all missed calls to __() by inserting an empty record in the database. You can now easily get a list of words/phrases that need to be translated.

    Hope that helps a bit.

  4. #4
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken View Post
    Another thing you can so, is to use the English phrase as the label. So instead of __("HOME_TITLE"), you would write __("Frontpage"). Since you already have the content in English, it would be much faster to change it.
    The problem with this, as opposed to the labels approach, is that the french phrase remains linked with the english one, so that if you change it from "Frontpage" to "Welcome" you have to update the links.

    BTW multilanguage problems were one of the reasons why makrell was invented. This is how I do it:

    Code:
    main.tpl:
    
    <body>
    <h1 class="super">hello</h1>
    etc
    
    
    main.en.tpl:
    
    {{include main.tpl}}
    hello {{ Welcome to our site }}
    
    
    main.de.tpl:
    
    {{include main.tpl}}
    hello {{ Willkommen auf unsere Seite }}
    
    php:
    
    $html = $makrell->parse_file("main_$lang.tpl");

  5. #5
    SitePoint Addict Jasper Bekkers's Avatar
    Join Date
    May 2007
    Location
    The Netherlands
    Posts
    282
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken View Post
    If you use gettext, then it's done for you already, otherwise you can just invent your own. I use two underscores, eg. __("HOME_TITLE").
    Notice that all symbols starting with two underscores are reserved for PHP. My advice is to use either t() or l() or anything else that's short.

    Quote Originally Posted by stereofrog View Post
    The problem with this, as opposed to the labels approach, is that the french phrase remains linked with the english one, so that if you change it from "Frontpage" to "Welcome" you have to update the links.
    No you create a new locale that links the english in the source code to the english you want it to be. Eg. you change the Frontpage to Welcome in the english .mo file (in case of gettext) but leave the text Frontpage in the application itself. This doesn't break the application an requires a minimal .mo file.

    A word of warning on gettext though; the setlocale function is not thread-safe so if you'll have to change the locale dynamically don't use it. See setlocale() for more information.
    Design patterns: trying to do Smalltalk in Java.
    I blog too, you know.

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    kyberfabrikken: Yes, that is just a particular implementation. But as far as I understood Loiusstart needed to be pointed in the direction of a scalable and maintainable solution for his problem. This is one of them.

    I agree with kyberfabrikken, I am afraid there is no easy way. The selected approach seems to me both hard to scale and maintain. If these are important elements for your page, I would consider a complete refactoring. Using databased for translating static text seems like a poor idea to me, and makes it hard to maintain (both translations and code) and challenging performance wise .

    If you were using gettext for this you would have two (or more if several people are translating at the same time) files to work on, and poedit would easily tell you if there are any changes made to the translation etc. It is also very easy to add several languages since on only need to create the translation file and start translating.

  7. #7
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jasper Bekkers View Post

    No you create a new locale that links the english in the source code to the english you want it to be. Eg. you change the Frontpage to Welcome in the english .mo file (in case of gettext) but leave the text Frontpage in the application itself.
    So this is essentially the "label" approach?

  8. #8
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stereofrog View Post
    So this is essentially the "label" approach?
    Yes, except that the default is to print the label itself.

  9. #9
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jasper Bekkers View Post
    Notice that all symbols starting with two underscores are reserved for PHP. My advice is to use either t() or l() or anything else that's short.
    Good point.

  10. #10
    SitePoint Addict Jasper Bekkers's Avatar
    Join Date
    May 2007
    Location
    The Netherlands
    Posts
    282
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stereofrog View Post
    So this is essentially the "label" approach?
    Yes, like kyber said, it defaults to printing the label. However, any changes you make to the text happen in the translation files instead of the source-code. (That is, unless the changes should break).
    Design patterns: trying to do Smalltalk in Java.
    I blog too, you know.

  11. #11
    SitePoint Zealot
    Join Date
    Aug 2007
    Location
    Toronto
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken View Post
    Another thing you can so, is to use the English phrase as the label. So instead of __("HOME_TITLE"), you would write __("Frontpage"). Since you already have the content in English, it would be much faster to change it.
    Hi, K. Thanks for the response. What exactly do you mean by the above? I don't see how that would make any difference. The text "HOME_TITLE" is actually just a custom name for the label that holds the actual content. So why would it matter to change it to say "Frontpage"?

    Thanks,

    Louis.

  12. #12
    SitePoint Addict Jasper Bekkers's Avatar
    Join Date
    May 2007
    Location
    The Netherlands
    Posts
    282
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Louistar View Post
    Hi, K. Thanks for the response. What exactly do you mean by the above? I don't see how that would make any difference. The text "HOME_TITLE" is actually just a custom name for the label that holds the actual content. So why would it matter to change it to say "Frontpage"?

    Thanks,

    Louis.
    Because that way you always have a user friendly 'backup' text that you can display. This means that you don't necessarily need to have a complete translation before shipping. It's also easier for the translators because they already have a complete text (instead of some arbitrary label).
    Design patterns: trying to do Smalltalk in Java.
    I blog too, you know.

  13. #13
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jasper Bekkers View Post
    Because that way you always have a user friendly 'backup' text that you can display. This means that you don't necessarily need to have a complete translation before shipping. It's also easier for the translators because they already have a complete text (instead of some arbitrary label).
    Also, the work process changes from:
    Find all localised text in file. For each, make up a label and then cut it out, replace with the label and finally paste label + localised text into external file.

    to:
    Find all localised text in file. For each, surround it with t().

    Much simpler.

  14. #14
    SitePoint Addict Jasper Bekkers's Avatar
    Join Date
    May 2007
    Location
    The Netherlands
    Posts
    282
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken View Post
    Much simpler.
    I usually set this stuff up right from the beginning anyway, clients tend to change their this sort of stuff quite often in my experience.
    Design patterns: trying to do Smalltalk in Java.
    I blog too, you know.

  15. #15
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jasper Bekkers View Post
    I usually set this stuff up right from the beginning anyway, clients tend to change their this sort of stuff quite often in my experience.
    Yes, I was mostly relating it to Louis' situation, as (s)he described it.

  16. #16
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I like to do it the french translation Thanks for sharing this.
    say a word in a hart french translation

  17. #17
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Plano
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry to waste a post without content, but it would only let me add one tag to the thread (wtf...why?) so i'm going to use the word i18n and internationalization so people on the internets can find this thread by searching.

    that is all.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •