geddy / model

Datastore-agnostic ORM in JavaScript
265 stars 55 forks source link

i18n Support in Model #178

Closed artzstudio closed 10 years ago

artzstudio commented 10 years ago

How is i18n integrated with Model (i.e. validation translations)? I see support for it in the code and clearly Geddy supports it, but this does not appear to be documented.

mde commented 10 years ago

I18n is implemented with the very small i18n library in the Utilities module: https://github.com/mde/utilities/blob/master/lib/i18n.js

When used as part of Geddy, we load up all these locales for Model's validations:

https://github.com/geddy/geddy/tree/master/gen/locales

We should probably pull these out into a separate repo that is in an obvious, documented place, and can be installed directly into Model when used outside of Ged.

artzstudio commented 10 years ago

It would definitely be ideal to break it out to provide flexibility for those that have their own favorite i18n lib. Since I'm still early in my project I'll give yours a go -- however it could also use some docs. ;)

Update: Just realized since Model is a dependency I don't have a way to share the i18n module instance and its loaded locales, guess this is what you meant by being "installed directly into Model".

My Plan B is to simply take the [[model.validatesPresent]] output and translate that from the view, unless this issue happily fits into your current priorities. Thanks!

mde commented 10 years ago

The parametric replacement (e.g., i18n.getText('model.validatesFormat', {name: name}, locale);) would make translating after the fact probably more irritating than just bootstrapping the i18n module. The Geddy code that loads the locales is actually really simple:

https://github.com/geddy/geddy/blob/master/lib/init/i18n.js

It's just passing JS objects to the i18n.loadLocale method.

artzstudio commented 10 years ago

Rookie mistake, I was requiring a different version of your utilities library than the one in Model, and thus was not sharing the same module. Thanks man!

mde commented 10 years ago

Glad it's sorted!