gbif-api icon indicating copy to clipboard operation
gbif-api copied to clipboard

Extend Language to ISO 639-3 codes

Open mdoering opened this issue 6 years ago • 7 comments

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 avatar Oct 08 '18 11:10 mdoering

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 avatar Oct 08 '18 11:10 mdoering

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

mdoering avatar Oct 08 '18 11:10 mdoering

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

mdoering avatar Oct 08 '18 11:10 mdoering

This will be covered in #51

marcos-lg avatar Mar 24 '20 15:03 marcos-lg

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 avatar Aug 26 '20 15:08 MattBlissett

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.

MattBlissett avatar Aug 26 '20 15:08 MattBlissett

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

mike-podolskiy90 avatar Aug 26 '20 21:08 mike-podolskiy90