Closed martingg88 closed 9 years ago
Take a look at supplemental/territoryInfo.
try to review the file. in between, i realize one country may have more than one languagePopulation, so which one of language is more reliable to pick up for specific country? should i based on _populationPercent to pick up the right language?
You'll notice there's a field populationPercent
that shows the most used one per territory. Please, just let me know in any further questions.
cool. but the language code is not consistent in \main\ms-Latn\languages.json.
as we know 'ms_Latn' could be the main language for MY country. However we may not find any 'ms_Latn' in \main\ms-Latn\languages.json (note: refer to localeDisplayNames.languages). Thus we may have some issue to find/match language in any part of project. any idea how to solve this issue?
"MY": {
"_gdp": "525000000000",
"_literacyPercent": "93.1",
"_population": "30073400",
"languagePopulation": {
"ms_Latn": {
"_officialStatus": "official",
"_populationPercent": "75"
},
},
However we may not find any 'ms_Latn' in \main\ms-Latn\languages.json
No, because ms-Latn
means ms
language, Latn
script. Therefore, you look for ms
in there.
I suggest you use https://github.com/rxaviers/cldrjs for traversing the data. By using cldrjs, you can:
npm install cldr-data cldrjs
var Cldr = require("cldrjs");
Cldr.load(require("cldr-data/main/ms-Latn/languages"));
var cldr = new Cldr("ms-Latn");
cldr.main("localeDisplayNames/languages/{language}");
// > 'Bahasa Melayu'
ok...thanks.
@rxaviers i do have one question here. thanks.
how to make sure this ISO format (etc: language-country/en-US) is apply to my project by using this cldr data library?
I feel strange cldr data doesn't follow this format as some languages do not append with country code.
@martingg88 I didn't understand your question? Could you reformulate it please?
i realize that cldr have some languages that do not append with country code. these languages are as follow:
how to make sure the language always follow this format as follows.
I recommend reading What is a Locale? :)
If you are using cldrjs, it takes care of the normalization for you. For example,
var Cldr = require("cldrjs");
Cldr.load(
require("cldr-data/supplemental/likelySubtags"), // Note you need to load likelySubtags.
require("cldr-data/main/en/languages")
);
var cldr = new Cldr("en");
cldr.main("localeDisplayNames/languages/{language}");
// > 'English'
var cldr = new Cldr("en-US");
cldr.main("localeDisplayNames/languages/{language}");
// > 'English'
var cldr = new Cldr("en-Latn");
cldr.main("localeDisplayNames/languages/{language}");
// > 'English'
var cldr = new Cldr("en-Latn-US");
cldr.main("localeDisplayNames/languages/{language}");
// > 'English'
many thanks for your answer.
this should produce "American English" instead. It make more sense than "English". right?
a. i'm trying to generate a list of language (that is supported by cldr data) for selection purpose. b. i will not get standard language ISO format if i based on cldr.main("localeDisplayNames/languages" ). c. what can i do to generate a list that its language code will follow ISO format (etc: language code-country code)?
en-US = "America English"
en-GB = "UK English"
ms-MY = "Bahasa Melayu"
It's very easy to accomplish what you want by iterating over the whole localeDisplayNames/languages
. I don't know what you mean by "language ISO format".
but some of languages do not follow this format. (language code-country code) refer to ISO format.
any idea how to make sure all languages follow this format (language code-country code) (etc: en-US)
Does it help you?
var locale = "en";
var Cldr = require("cldrjs");
Cldr.load(require("cldr-data/main/" + locale + "/languages"));
var cldr = new Cldr(locale);
cldr.main("localeDisplayNames/languages");
// > { aa: "Afar",
// ab: "Abkhazian",
// ...
// }
Object.keys(cldr.main("localeDisplayNames/languages")).map(function(locale) {
return cldr.main(["localeDisplayNames/languages", locale]);
});
// > [ "Afar",
// "Abkhazian",
// ...
// ]
i should be able to generate list like following. But my question is how to make left hand side which is language code to follow this format (language_code-country_code)? so i expect all the language code in following list should be appended with country code (etc: en-US, en-GB, en-SG).
{ aa: "Afar", ab: "Abkhazian", ... }
@martingg88 I hope all the above makes it clear on how you could accomplish what you need.
anyway. thanks for your effort.
how can i find the main language used for specific country.
For example if i give "US" as country code. what is the method/files i need to find the main language for "US" country?