Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Accessing translations from missing-message util #322

Closed
ofridagan opened this issue Oct 8, 2015 · 8 comments
Closed

Accessing translations from missing-message util #322

ofridagan opened this issue Oct 8, 2015 · 8 comments

Comments

@ofridagan
Copy link
Contributor

It would be nice if we could access the I18n service from utils/i18n/missing-message.js
This way we could implement a default fallback language for example..

@jamesarosen
Copy link
Owner

Interesting. The current signature is

function missingMessage(locale, key, data)

We could add I18n to that:

function missingMessage(locale, key, data, i18n)

@thagul
Copy link

thagul commented Oct 8, 2015

It would be great because with that change I could send a notification for the missing translation but also display the english version (english is my fallback).

@jamesarosen
Copy link
Owner

I suppose it could alternatively be called on the I18n service, so you could do

function missingMessage(locale, key, data) {
  return this.t('missing-translation', { key: key, locale: 'en' });
}

I'm not sure that's as obvious, though.

@thagul
Copy link

thagul commented Oct 9, 2015

@jamesarosen I didn't understand your last message. Are you saying that I can already do what I need?

Let me make an example of my needs. I've two language files en and it. EN is my base language and it's always complete, it may have problems.

English file contains:

{
"label1": "Homepage",
"label2": "Contact us",
"label3": "About us"
}

Italian file contains:

{
"label1": "Homepage",
"label2": "Contact us"
}

label3: about us is missing (I've forgot it or I haven't translated yet, it's the same).

When the user visit my application, I don't wan't to show him a Missing translation: label3 message but I would show him the english version. In the meantime I would receive an alert to get informed of the missing translation (I've already configured ember to send an email when an error occurs).

Any suggestion on how can do that?
Many thanks

@jamesarosen
Copy link
Owner

I was discussing alternative implementation ideas, not suggesting it was already possible. Would you be willing and able to make a PR to add i18n as a final argument to missingMessage? That area of the code is pretty well tested; it should be pretty easy to add another test.

@ofridagan
Copy link
Contributor Author

@jamesarosen yes, this is what I had in mind.
I created a PR with the simple fix: #323

@ofridagan
Copy link
Contributor Author

btw, even with this fix, what would be the best way to implement a default locale?
One option I see is instantiating a Locale object, and use that... but it seems very hacky.
I tried to do something like: i18n.t(key, {locale: 'en'}) but it doesn't work...

@jamesarosen
Copy link
Owner

See #256 for a discussion of falling back to a default locale.

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

No branches or pull requests

3 participants