Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Default fallback for country variant #26

Closed
btd opened this issue Oct 16, 2015 · 4 comments
Closed

Question: Default fallback for country variant #26

btd opened this issue Oct 16, 2015 · 4 comments

Comments

@btd
Copy link

btd commented Oct 16, 2015

Hello.

I would like to ask question about using country variants:

var BabelFish = require('babelfish');
var i18n = new BabelFish('en-GB');
i18n.addPhrase('pt', 'test.a', 'Apelido')
i18n.addPhrase('pt-BR', 'test.a', 'Sobrenome')
i18n.addPhrase('pt', 'test.b', 'Título')
> i18n.t('pt', 'test.a')
'Apelido'
> i18n.t('pt-BR', 'test.a')
'Sobrenome'
> i18n.t('pt-BR', 'test.b')
'pt-BR: No translation for [test.b]'

Shouldn't last line fallback to 'pt' ? Or i should manually add every possible fallback with .setFallback?

Thanks.

@puzrin
Copy link
Member

puzrin commented Oct 16, 2015

There are no such auto-fallbacks, because those are not acceptable in 100% of use cases. Use .setFallback() to define exact rules.

@btd
Copy link
Author

btd commented Oct 16, 2015

Ok, thanks. Agree in general but FYI for pt-BR default is pt as defined there http://cldr.unicode.org/translation/default-content. Anyway i think i will better to add pt-PT and pt-BR instead of reinventing wheels.

@btd btd closed this as completed Oct 16, 2015
@puzrin
Copy link
Member

puzrin commented Oct 16, 2015

Usually people use base names only (ru) or full names only (ru-RU) for all project. It's unordinary to have both translations and such fallback is not required at all.

Probably, you mean locale "autodetection", when browser sends "ru; ru-RU;". But this happens before babelfish call and usually normalize locale names length, according to your project needs. For example: https://github.com/nodeca/nodeca.core/blob/master/lib/autoload/hooks/server_chain/locale_set.js

@btd
Copy link
Author

btd commented Oct 16, 2015

Yes, that is similar with what i want, will add preprocessing to set fallbacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants