country-coder icon indicating copy to clipboard operation
country-coder copied to clipboard

Add ISO639 official language codes

Open missinglink opened this issue 2 years ago • 3 comments

As discussed in https://github.com/rapideditor/country-coder/issues/131

Preview: Screenshot 2023-09-06 at 15 45 19

Code:

import fs from 'fs'
const borders = JSON.parse(fs.readFileSync('borders.json'))
const langs = JSON.parse(fs.readFileSync('langs.json'))

console.log(`{"type":"FeatureCollection","features":[`)
borders.features.forEach((f, o) => {
  const l = langs[f.properties.iso1A2]
  if (l) f.properties.iso639 = l

  const comma = o < (borders.features.length-1)
  console.log(JSON.stringify(f) + (comma ? ',' : ''))
})
process.stdout.write(`]}`)

missinglink avatar Sep 06 '23 13:09 missinglink

I think these are technically named ISO 639-1 codes, let me know if you think I should rename the field.

missinglink avatar Sep 06 '23 13:09 missinglink

Maybe I should also split the strings into an array 🤔

missinglink avatar Sep 06 '23 13:09 missinglink

These are technically BCP 47 language tags, which include ISO 639-1 and -2 and -3 language codes combined with ISO 3166 country codes. It doesn’t seem to include any ISO 15924 script codes, which would be important for any Serbian- or Chinese-speaking region.

1ec5 avatar Sep 06 '23 16:09 1ec5