5 ms·
Internationalizing your Rails Application
- shpiel 13y agoOne of the most annoying things about translation is that the length of the string may change which can mess up designs and layouts. For example German strings tend to be longer than their English equivalents. Or dealing with languages which orientation is right to left (eg. Hebrew).
- Gigablah 13y agoAnd sometimes you might have the same word or phrase in multiple locations that translate differently depending on context.
- byroot 13y agoThat's why rails do no use source locale as translation keys but a dot notation e.g. "homepage.posts.title"
- colinsidoti 13y agoAt an airbnb techtalk they stressed how this is a really annoying problem for them. They actually have a subdomain that substitutes longer than normal english strings within their design: https://xxlong.airbnb.com/ https://xxlong.airbnb.com/
- Groxx 13y agoThat's a pretty common approach. In Rails it's also not too hard to monkey patch I18n in development to e.g. double every string it returns, or throw in random UTF characters. The hard part I've encountered is that you have to think about text differently. Things that are identical in English but have different semantic meanings must be split. Plurals. Almost-never concatenating or .join(',')ing or .split()ing. It's pretty easy to write yourself into a corner unless you stick to doing it right all the time, which takes some time to learn.
- tr8n 13y agoThis is a very tricky issue. Tr8n somewhat solves it by allowing developers to specify translation key constraints for critical sections right in the code. The constraints make the translation key unique, give an indication to translators what they need to do and enforces the translators submissions. For example: <%= tr("App", :max_length => 6) %> If translators try to submit something longer than 6 chars, they will get a warning to adjust to the constraints. In Russian "App" is "Приложение". So they would have to provide something shorter or an abbreviation.
- jimeuxx 13y agoI've found this to be a bit of a nightmare with Japanese and English. Japanese DVD and CD titles often have a mix of both languages, so length becomes next to meaningless when comparing Japanese strings even against themselves. The feel of the text is also completely different, which makes it hard to balance the layout for both languages.
- nathanappere 13y agoFor the javascript part: https://github.com/fnando/i18n-js https://github.com/fnando/i18n-js
- tr8n 13y agoHave you ever heard of Tr8n? http://github.com/tr8n http://github.com/tr8n And specifically Tr8n for RoR: https://github.com/tr8n/tr8n_rails_clientsdk https://github.com/tr8n/tr8n_rails_clientsdk It is a powerful translation framework, which significantly simplifies the translation process, while improving your code readability. First of all you don't need to deal with resources bundles at all - use English keys right in the code. Tr8n takes care of the rest. <%= tr("Hello World") %> Dynamic data tokens are very easy to work with: <%= tr("Hello {user}", :user => "Michael") %> It fully supports language context rules: <%= tr("You have {count||message}", :count => 10) %> <%= tr("{user|He, She} likes this", :user => some_user) %> <%= tr("{users||likes, like} this a lot", :user => some_users) %> It even supports language cases: <%= tr("{actor} likes {target::possessive} message", ...) %> Tr8n uses TML (Translation Markup Language) to define translation keys that now an be shared across all platforms and applications (mobile, web, desktop). TML can easily handle data and decoration tokens within the same key context: <%= tr("You have [bold: {count||message}]", :count => 10, :bold => lambda{|t| "<strong>${t}</strong>"}) %> <%= tr("This is indeed [bold] a very [italic: powerful] framework]",...) %> You can predefine all your lambdas elsewhere and use default data and decorations throughout your app. The same sentence above, since it uses TML instead of hardcoded HTML, will actually produce an NSAttributedString in iOS properly decorated in any language. Tr8n is used in conjunction with Tr8nHub.com where you have access to UTM (Universal Translation Memory) - a huge database of translations used across all applications. You may get fully translated by just connecting to it. Disclosure: I've been working on Tr8n for the past 4 years, constantly improving it. We are about to launch a new site soon that will make a lot of things much cleaner and easier. The framework is used by companies like Yammer and Geni. I forgot to mention that you get inline translation tools, translation widgets, and a lot more...
- tr8n 13y agoTypo in one of the examples: <%= tr("This is indeed [bold] a very [italic: powerful] framework [/bold]",...) %> Decoration tokens have short and long forms: <%= tr("This is [bold: cool]") %> <%= tr("This is [bold]cool[/bold]") %>
- Groxx 13y agoHmmm. I like the idea of a shared database, but on the flipside you "only" need your developers to precisely understand the language they're using. The vast majority of people have no need for a deep understanding of their native language, I'd be worried about subtly-wrong translations. Something is better than nothing, but weird is still bad. For example, you use "you" in "You have {count||message}" - there's no gender or other meaning encoded, it'll probably be a bit off for some languages. More technically: how does this translate? >This is indeed [bold] a very [italic: powerful] framework][/bold] To make a hypothetical worst-case scenario, say one of the target languages combines "this" and "powerful" into a single word, splits "framework" into three, and reorders it so conceptually you flip between bold and italic and plain practically at random. There's (probably) an element of aesthetics combined with the text's meaning, can the crowd detect that aesthetic? What if it varies all over your site because it's sourcing from different crowds? Similarly, say you refer to "this" thing on the website/app, which is up and a little to the right, but not this other thing to the left. RTL probably switches that, and does "up and a little to the right" have an encoding in TML so that the meaning is retained if a language has a specific word for that?