Closed limoragni closed 8 years ago
That seems reasonable, but would be a breaking change. What about adding an alternative option that returns undefined
or false
or something?
An option like allowMissing but returning false/undefined when there is no matches? I think that would be enough.
Is there any way to achieve this? I'm thinking something like if(polyglot.t("key") === "key")
the translation doesn't exists. But this solution is really ugly, and not work all the time for me.
@pleivac you can use polyglot.has(key)
to determine if the phrase is present or not.
Perfect @ljharb... Many many thanks!
@limoragni @pleivac I've filed #77 to address this in a more generic manner. Please let me know if that will resolve your use cases.
@ljharb yes, I think onMissingKey is a great solution!
I'm using polyglot for translating dynamically generated strings and I would like to have a way of knowing when a translation is not available.
For what I saw in the code the allowMissing just pass the string to the choosePluralForm and interpolate methods. But if allowMissing is false, it just returns the key used for the translation. The keys I'm using are in some cases numerical codes that refers to strings in different languages, so having the key back breaks my code silently.
Apart for the warning I think that result should be false. What do you think?