gbif / gbif-api

GBIF API
Apache License 2.0
27 stars 5 forks source link

Extend Language to ISO 639-3 codes #29

Open mdoering opened 5 years ago

mdoering commented 5 years ago

Based on gbif/checklistbank#73 we need to deal with more languages than the current enum based on ISO 639-2 codes holds. The simplest option would be to extend the Language enum with all ~7700 codes and store both 2 and 3 letter codes as enum properties. But is a large enum like this still a good idea? Enum values are only initialised when they are first used, so should not be a JVM issue

mdoering commented 5 years ago

we have 186 entries now and use Locale to retrieve an english and native title. That would also need to be explicitly listed in the extended enum

mdoering commented 5 years ago

The official list has only english titles: https://iso639-3.sil.org/sites/iso639-3/files/downloads/iso-639-3.tab

mdoering commented 5 years ago

I've quickly tried an extended enum and its not gonna work. Compilation error "Java code too large"

marcos-lg commented 4 years ago

This will be covered in #51

MattBlissett commented 3 years ago

Proposal:

Use java.util.Locale, with the property name languageTag, and serialize using BCP-47 (.toLanguageTag()). Alternatively, store just a String languageTag, specified to be BCP-47, and parse using Locale.

This seems to support pretty much everything, and moves the question of what values should be allowed to the classes. "Website language" might need 6+ constants defined, "User language" would need a list of living languages, and checklists can record any language -- it's up to the parser to decide what to do with fr, fr-LU and fr-FR.

new Locale.Builder()
  .setLanguage("zh").setScript("Hant").build().toLanguageTag() 
→ "zh-Hant"

new Locale.Builder()
  .setLanguage("es").setRegion("419").build().getDisplayName() 
→ "Spanish (Latin America and the Caribbean)"

// All the bits for Locale("en", "GB"):
en_GB
en
English
英文  // getDisplayLanguage(Locale.SIMPLIFIED_CHINESE)
GB
United Kingdom
English (United Kingdom)
eng
// (no script)
en-GB // toLanguageTag()
MattBlissett commented 3 years ago

I've run all the Crowdin language through Locale.Builder()... and it works. Crowdin include Klingon, en_JA (Jamaica is JM, and en_JM is present and works) and some other non-ISO codes. They can be stored in a Locale and retrieved, but the meanings might not be in Locale's dictionary.

All the GBIF Language enumeration values parse fine.

mike-podolskiy90 commented 3 years ago

I'll try GbifUser with the Locale. Do we have add locale to the Organization class?