Is there a standard locale resolution algorithm?

In support of software internationalization, many programming languages ​​and platforms support a tool for retrieving localized resources that will be used in the user interface that is shown to the user (for example, Java java.util.ResourceBundle ). Often, if the resources for the user who prefers the locale are unavailable, then there is a return mechanism or a process for resolving the locale that will try to find the nearest matching resources from the sets of available resources. For example, if resources for en-US not available, usually the system tries to find resources for en .

The locale resolution process seems pretty much the same for resource pack solutions in many languages ​​and platforms. Are they consistent with standard locale resolution algorithms, or if not, does such a standard exist?

+6
source share
3 answers

I do not know about the standard as such.

However, the algorithm used is a trivial consequence of the fact that locales are hierarchical. There is a (conditional) root locale with no name. Under this are only local languages ​​(en, fr, etc.). Below them are the national locales (en_GB, en_US, etc.). Below them are possibly locale options (en_GB_Yorkshire, en_GB_cockney, etc.) For realistic examples, look at Norway).

The natural way to find a suitable resource is to start from the lowest, most specific locale that you can, and go to the tree until you find something. So, starting with en_US_TX, you go to en_US, then en, then to the root.

+1
source

Apparently, RFC 4647 , "Matching Language Tags", which describes the syntax of "language ranges" for specifying a list of users, preferred languages, as well as the "filter" and "search" mechanisms for comparing and matching language ranges with the language tags of RFC 4646. RFC 4647 describes these mechanisms as:

Filtering creates a (potentially empty) set of language tags, while lookup creates a single language tag.

+2
source

CLDR - Unicode Common Locale Data Repository offers the proposed (as of 2015) algorithm based on the distance between languages . Without distance data, this is not a solution, but it is worth looking at a solution in the future.

+1
source

Source: https://habr.com/ru/post/904548/


All Articles