Currently, the translator receives an array of locales. Its constructor selects the locale object that matches the language parameter, and the remaining locale objects are essentially thrown away, nothing utilizes them in the translator instance.
To switch to a new language, a new translator instance is created every time. This is inefficient.
There is no point in providing an array of locale data to the constructor if only one locale object is ever used.
I think some changes should be made:
Constructor should be allowed to receive a single object instead of an array with one object (this is not critical, but makes sense).
Add a new instance method that allows adding locale data to the instance. This would allow lingui-like dynamic loading of messages.
Add a new instance method that allows switching between language and locale data without creating a new instance.
Currently, the translator receives an array of locales. Its constructor selects the locale object that matches the
language
parameter, and the remaining locale objects are essentially thrown away, nothing utilizes them in the translator instance.I think some changes should be made: