SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multi-Language Support for dynamic content

    One of the websites I operate has a very international focus, and I'm trying to figure out the best way to start providing multi-lingual content to its users. I'm familiar with the technical side of i18n support in PHP; there are a lot of good tools out there to help, so I don't feel too lost there. I am, however, very confused about how to provide translations for dynamic, database-stored content as opposed to simply translating static phrases in the PHP scripts themselves. In other words, assuming that $translator is a proper instance of, say, Zend_Translate...

    PHP Code:
    // This is easy...
    echo $translator->_('Static Interface Text');

    // This is not so easy...
    echo $translator->_($variablePopulatedAtRuntimeFromDatabase); 
    The reasons the second one is so hard for me to wrap my mind around:

    1. The value of that variable will likely change pretty often; how do I ensure that translation files (MOs, TMXs, etc.) are kept up-to-date in tandem with the database itself?
    2. The value of that variable is often pretty long; is it best to translate the whole thing at once or somehow break it into smaller chunks? If the latter, how in the world do I do that reliably?
    3. In the above example, the value of the variable is also its translation ID (in TMX terms, I believe that's its 'tuid' value, right?). However, it seems that including the full database value in the translation file is really, really redundant.


    Regarding option 1, I've thought about extending Zend_Translate with additional methods for dynamically adding new translation units to the translation file.

    Regarding option 2...well, I really can't find my way around that at all.

    Regarding option 3, the main thing I can think of is to implement separate translation files for each database table and then use some combination of primary key value and field name as the 'tuid'. Alternatively, I suppose I could set up separate database tables for each language, but that would require a DbTable adapter for Zend_Translate, which isn't ready yet.

    What do you folks do when you have to support multiple languages in dynamic content?

    (As a side note...if this is not PHP-specific enough to belong in the PHP forum, I apologize; please feel free to move the thread to a more relevant location if necessary. I'm posting here mainly because I need to do this in PHP, but I realize that these issues may be more general than that.)

  2. #2
    SitePoint Addict
    Join Date
    Aug 2007
    Location
    GR
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by _Steve_ View Post
    Thanks for the tip; I especially like the availability of a code scanner for picking out strings that need translating.

    However, of the two examples in my original post, it looks as though poEdit can only help me with the first one. I don't think it can automatically generate a PO when the argument passed to the _ function is a variable rather than an explicit value.

    If this is the case, then poEdit can't really help me figure out how to keep my PO templates up-to-date with the master database, even though it can help me do the translations once the PO files are created.

    In other words, I'm more interested in how to create a consistently up-to-date translation file template than in how to get it actually translated.

  4. #4
    SitePoint Addict
    Join Date
    Aug 2007
    Location
    GR
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let me put it differently...is there a PHP library available that can modify a PO or TMX translation file template at runtime? That is, if my application tries to translate the phrase, 'This sentence needs translating.' and it's not found in the existing translation file, I could add it to the translation file dynamically?

    This would make translating database content so much easier. Maybe I should write it myself, but it'd be nice to leverage existing code if it's already out there.

  6. #6
    SitePoint Member
    Join Date
    Sep 2006
    Location
    Budapest, Hungary
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am also working on a multi-lingual site, and I happen to use the Zend Framework for this as well. For the static contents I use Zend_Translate and the gettext adapter, while I have created separate column in each database table for each languages (since I am only planning to support a limited number of languages, this seemed to be a good enogh solution) to store the translations of dynamic contents. Although I have tried to make everything easily expandable, this structure requires minor database and code modification when new languages are added.
    For the translation part I will simply create a user interface, where a translator can simply translate the text sentence by sentence. Static texts are translated in po/mo files with poEdit.
    Have you come up with any better solution since your last post?


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
  •