Hi, We have a multilingual application using I18n, How would you test your application have no translations missings ? Would you test it view by view ? or have you a better solution ? Thanks,
on 2010-10-12 11:38
on 2010-10-12 21:46
Hi, My first guess: When you have view specs or controller specs with render_views/integrate_views you could make I18n raise an error when its missing a translation. Then run every spec in every locale and you'll see where there are missing. This might be a lot of work and you won't get translations that have a default (like human_attribute_name). So, my second guess: You'll probably have one base locale, the one you work in. If you consider that one to be complete, you can compare the keys from each translation. You'll have to flatten them first though. This isn't easy too. So, I hope you have some ideas from this. Good luck, and share the answer if you find it :) cheers, iain
on 2010-10-13 11:55
Hi Iain, Thanks for the reply, I was thinking of the 2nd solution but it fails if we forget translations in the main language. I was hoping there's maybe a way to scan the code via a rake task, find ALL the keys used in the code and compare them to the one declared in locales but it's maybe way more work ... Thanks for your help. cheers, Mike
on 2010-10-13 19:34
You can do this to intercept any missing translations when you restart
your app:
module I18n
class << self
def raise_custom_exception(exception, locale, key, options)
if MissingTranslationData === exception
# do something with the missing translation
return translation
else
raise exception
end
end
end
end
I18n.exception_handler = :raise_custom_exception
I've used it to make a call to the google translate API to generate
any missing machine translation(s), and then push them to my backend
so I have them for next time.
Hope that helps!
Shelly
http://wordchuck.com
--
on 2010-10-14 05:20
When people ask about missing translations I wonder if they mean missing lookups instead. If you do I18n.t(:missing, :default => :not_missing) then you won't get into the I18n.exception_handler routine as there is no missing translation. But there is a missing lookup. If you use the gettext helpers then by definition there are no missing translations, only missing lookups. In the end I came to the conclusion that it is an impossible task to find missing translations by running or testing the app. See also: http://github.com/svenfuchs/i18n/blob/master/lib/i18n/backend/active_record/missing.rb Cheers, Lawrence
on 2010-10-14 07:36
Eyes are the windows to the world. Are your caring for it? If not, then this World Sight Day, visit your nearest optometrist and get your eye test done? Check out for more http://www.facebook.com/WorldSightDay
on 2010-10-15 12:53
Hey guys thanx for the awesome replies ! Andrs, hope you're doing good and enjoying France :-) You're right I didn't think of this cases and we have quite a few in our app. Shelly, nice piece of code but as Lawrence said it won't work if you're using a default translation. Lawrence thanks for pointing me this extension, it seems very nice. I'll implement that :-) Cheers, Mike
on 2010-10-15 22:59
Hi Mike,
That can be done but it won't help when you have dynamic keys like
I18n.t("users.show.#{current_user.favorite_meal}")
Cheers,
Andrs Meja
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.