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

Allow to pass custom Cldr module #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dolfinus
Copy link
Contributor

@dolfinus dolfinus commented Nov 16, 2020

If one uses any language defined in Linguist.Cldr, it's fine, linguist will handle translations as usual.
If one uses any language which is unknown for Linguist.Cldr, but does not use pluralized keys, this is also fine - such operations as key search and string interpolation are also handled as usual.

But if one uses unknown language and a path which should be pluralized by Cldr, the error will be raised:

     ** (Protocol.UndefinedError) protocol String.Chars not implemented for {:error, {Cldr.UnknownLocaleError, "The locale \"ru\" is not known."}} of type Tuple. This protocol is implemented for the following type(s): Decimal, Date, URI, Time, Integer, Version.Requirement, DateTime, NaiveDateTime, Float, Atom, Version, BitString, List
     code: I18n.t("ru", "countable", count: 1)
     stacktrace:
       (elixir 1.11.0) lib/string/chars.ex:3: String.Chars.impl_for!/1
       (elixir 1.11.0) lib/string/chars.ex:22: String.Chars.to_string/1

This could be more annoying after #32, because fr and es locales will be removed from package default config.

In this PR I've added feature of passing custom Cldr backend module into linguist app.
Possible ways are described in README.md, there are plenty of them.

Also t() function will return {:error, _} without throwing any exception and t!() function will throw an exception which was returned from Cldr module instead of Protocol.UndefinedError.

WIP status is set because this fix depends on #31, which should be merged first.

@dolfinus dolfinus changed the title WIP: Allow to pass custom Cldr module Allow to pass custom Cldr module Feb 13, 2021
@dolfinus
Copy link
Contributor Author

@mertonium Could you please take a look at this?

@dolfinus
Copy link
Contributor Author

@mertonium I've rebased commits to current master state to run tests. What do you think about this PR?

@dolfinus dolfinus mentioned this pull request Apr 5, 2021
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

Successfully merging this pull request may close these issues.

1 participant