R.swift icon indicating copy to clipboard operation
R.swift copied to clipboard

Ability to set preferredLanguages globally

Open wvteijlingen opened this issue 3 years ago • 0 comments

Feature request

A way to set a global default for the preferredLanguages parameter. For example: R.string.localizable.preferredLanguages = ["nl_NL", "en_US"].

In the past there have been multiple requests for this, but it seems that it never got any traction. With this issue I would like to see if there is willingness from the core team to implement such a feature.


Reason behind the request

By default R.swift.string user the device language. If an app uses its own in-app language selector, the developer needs to pass a preferredLanguages array to every localised string function.

While this is a nice approach for one-off overrides, it has a couple of serious drawbacks if you want to use it throughout the entire codebase:

  1. Every call site now needs to be aware of the language that the user selected. So we either need to make that a global, or inject it into every object that needs a translated string. This will quickly get out of hand.
  2. The call site will be cluttered with an argument that is the same for every call: R.string.localizable.welcomeWithName("Arthur Dent", preferredLanguages: userSelectedLanguage).
  3. It's easy to forget passing the preferredLanguages argument, leading to localisation issues that are only present in runtime.

This issue is currently blocking us from adopting R.swift for localised strings, because we cannot make those tradeoffs.

wvteijlingen avatar Jan 13 '22 09:01 wvteijlingen