rapideditor / country-coder

📍➡️ 🇩🇰 Convert longitude-latitude pairs to ISO 3166-1 codes quickly and locally
https://ideditor.codes
ISC License
220 stars 17 forks source link

Add ISO639 official language codes #132

Open missinglink opened 10 months ago

missinglink commented 10 months ago

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 commented 10 months ago

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

missinglink commented 10 months ago

Maybe I should also split the strings into an array 🤔

1ec5 commented 10 months ago

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.