Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: dynamically load language locale maps #4089

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

L03TJ3
Copy link
Collaborator

@L03TJ3 L03TJ3 commented Sep 14, 2023

Description

dynamically load language label and country code maps based on supported lingui locales

  • - add setup for maps in i18n scripts
  • - translate English language names into their native locale

About # (link your issue here)
#4074

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • PR title matches follow: (Feature|Bug|Chore) Task Name
  • My code follows the style guidelines of this project
  • I have followed all the instructions described in the initial task (check Definitions of Done)
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have added reference to a related issue in the repository
  • I have added a detailed description of the changes proposed in the pull request. I am as descriptive as possible, assisting reviewers as much as possible.
  • I have added screenshots related to my pull request (for frontend tasks)
  • I have pasted a gif showing the feature.
  • @mentions of the person or team responsible for reviewing proposed changes

@vercel
Copy link

vercel bot commented Sep 14, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
good-dapp ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 14, 2023 8:50am
2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
gooddollar-delta ⬜️ Ignored (Inspect) Visit Preview Sep 14, 2023 8:50am
goodid ⬜️ Ignored (Inspect) Sep 14, 2023 8:50am


// map the filtered locales to a country code (used for retreiving flag icons)
// and their language name (used in language selector)
const localeCodeMap = filteredLocales.map(locale => {

Check notice

Code scanning / CodeQL

Unused variable, import, function or class

Unused variable localeCodeMap.
defaultValue={languageCustomLabels[countryCode] ?? t`Select a language...`}
options={[isWeb ? '' : 'DD', ...supportedCountryCodes]} // empty string breaks on native
defaultValue={languageLabels[countryCode] ?? t`Select a language...`}
options={[isWeb ? '' : 'DD', ...countryCodes]} // empty string breaks on native
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we still using this 'DD' ? empty value should mean 'system default'.

Copy link
Collaborator Author

@L03TJ3 L03TJ3 Sep 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We removed it but I had to turn it back here (on android)
the component is not able to handle a empty string when rendered on android (as comment points out)

@@ -111,7 +75,7 @@ const getKeyByValue = (object, value) => {
const DropDownRowComponent = props => {
const { containerStyles, textStyles, children } = props
const { children: countryCode } = children.props
const countryLabel = languageCustomLabels[countryCode] ?? 'Device Default'
const countryLabel = languageLabels[countryCode] ?? 'Device Default'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declare

const getLabel = code => languageLabels[code] ?? t`Device default`

helper outside component and use it

@@ -9,6 +9,39 @@ const { writeFileSync } = require('fs')
const package = require('../package.json')
const { locales, sourceLocale } = package.lingui


const lcid = require('windows-locale')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need the whole list.
lingui is actually based over Android-supported locales which are: https://developers.google.com/interactive-media-ads/docs/sdks/android/client-side/localization

(just the underscore char is replaced via dash)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I started an whole map:

const locales = {
  af: {
    label: "Afrikaans",
    countryCode: "ZA"
  },
  am: {
    label: "ኣማርኛ",
    countryCode: "ET"
  },
  ar: {
    label: "العربية الفصحى",
    countryCode: "AE"
  },
  ar_eg: {
    label: "عربى",
    countryCode: "EG"
  },
  ar_sa: {
    label: "العربية الفصحى",
    countryCode: "SA"
  },
  eu: {
    label: "Euskara",
    countryCode: "ES"
  },
  be: {
    label: "Беларуская",
    countryCode: "BY"
  },
  bn: {
    label: "Bengali",
    countryCode: null
  },
  bg: {
    label: "Bulgarian",
    countryCode: null
  },
  ca: {
    label: "Catalan",
    countryCode: null
  },
  zh: {
    label: "Chinese (Simplified)",
    countryCode: null
  },
  zh_cn: {
    label: "Chinese (Simplified, China)",
    countryCode: null
  },
  zh_hk: {
    label: "Chinese (Traditional, Hong Kong)",
    countryCode: null
  },
  zh_tw: {
    label: "Chinese (Traditional, Taiwan)",
    countryCode: null
  },
  hr: {
    label: "Croatian",
    countryCode: null
  },
  cs: {
    label: "Czech",
    countryCode: null
  },
  da: {
    label: "Danish",
    countryCode: null
  },
  nl: {
    label: "Dutch",
    countryCode: null
  },
  en: {
    label: "English",
    countryCode: null
  },
  en_au: {
    label: "English (Australia)",
    countryCode: null
  },
  en_ca: {
    label: "English (Canada)",
    countryCode: null
  },
  en_gb: {
    label: "English (United Kingdom)",
    countryCode: null
  },
  en_ie: {
    label: "English (Ireland)",
    countryCode: null
  },
  en_in: {
    label: "English (India)",
    countryCode: null
  },
  en_sg: {
    label: "English (Singapore)",
    countryCode: null
  },
  en_za: {
    label: "English (South Africa)",
    countryCode: null
  },
  et: {
    label: "Estonian",
    countryCode: null
  },
  fa: {
    label: "Farsi",
    countryCode: null
  },
  fil: {
    label: "Filipino",
    countryCode: null
  },
  fi: {
    label: "Finnish",
    countryCode: null
  },
  fr: {
    label: "French",
    countryCode: null
  },
  fr_ca: {
    label: "French (Canada)",
    countryCode: null
  },
  fr_ch: {
    label: "French (Switzerland)",
    countryCode: null
  },
  gl: {
    label: "Galician",
    countryCode: null
  },
  de: {
    label: "German",
    countryCode: null
  },
  de_at: {
    label: "German (Austria)",
    countryCode: null
  },
  el: {
    label: "Greek",
    countryCode: null
  },
  gu: {
    label: "Gujarati",
    countryCode: null
  },
  he: {
    label: "Hebrew",
    countryCode: null
  },
  hi: {
    label: "Hindi",
    countryCode: null
  },
  hu: {
    label: "Hungarian",
    countryCode: null
  },
  is: {
    label: "Icelandic",
    countryCode: null
  },
  id: {
    label: "Indonesian",
    countryCode: null
  },
  it: {
    label: "Italian",
    countryCode: null
  },
  ja: {
    label: "Japanese",
    countryCode: null
  },
  kn: {
    label: "Kannada",
    countryCode: null
  },
  ko: {
    label: "Korean",
    countryCode: null
  },
  lo: {
    label: "Lao",
    countryCode: null
  },
  lv: {
    label: "Latvian",
    countryCode: null
  },
  ln: {
    label: "Lingala",
    countryCode: null
  },
  lt: {
    label: "Lithuanian",
    countryCode: null
  },
  ms: {
    label: "Malay",
    countryCode: null
  },
  ml: {
    label: "Malayalam",
    countryCode: null
  },
  mr: {
    label: "Marathi",
    countryCode: null
  },
  no: {
    label: "Norwegian",
    countryCode: null
  },
  pl: {
    label: "Polish",
    countryCode: null
  },
  pt: {
    label: "Portuguese",
    countryCode: null
  },
  pt_br: {
    label: "Portuguese (Brazil)",
    countryCode: null
  },
  pt_pt: {
    label: "Portuguese (Portugal)",
    countryCode: null
  },
  ro: {
    label: "Romanian",
    countryCode: null
  },
  ru: {
    label: "Russian",
    countryCode: null
  },
  sr: {
    label: "Serbian",
    countryCode: null
  },
  sk: {
    label: "Slovak",
    countryCode: null
  },
  sl: {
    label: "Slovenian",
    countryCode: null
  },
  es: {
    label: "Spanish",
    countryCode: null
  },
  es_419: {
    label: "Spanish (Latin America)",
    countryCode: null
  },
  es_ar: {
    label: "Spanish (Argentina)",
    countryCode: null
  },
  es_cl: {
    label: "Spanish (Chile)",
    countryCode: null
  },
  es_co: {
    label: "Spanish (Colombia)",
    countryCode: null
  },
  es_cr: {
    label: "Spanish (Costa Rica)",
    countryCode: null
  },
  es_do: {
    label: "Spanish (Dominican Republic)",
    countryCode: null
  },
  es_ec: {
    label: "Spanish (Ecuador)",
    countryCode: null
  },
  es_sv: {
    label: "Spanish (El Salvador)",
    countryCode: null
  },
  es_gt: {
    label: "Spanish (Guatemala)",
    countryCode: null
  },
  es_hn: {
    label: "Spanish (Honduras)",
    countryCode: null
  },
  es_mx: {
    label: "Spanish (Mexico)",
    countryCode: null
  },
  es_ni: {
    label: "Spanish (Nicaragua)",
    countryCode: null
  },
  es_pa: {
    label: "Spanish (Panama)",
    countryCode: null
  },
  es_pe: {
    label: "Spanish (Peru)",
    countryCode: null
  },
  es_pr: {
    label: "Spanish (Puerto Rico)",
    countryCode: null
  },
  es_py: {
    label: "Spanish (Paraguay)",
    countryCode: null
  },
  es_us: {
    label: "Spanish (United States)",
    countryCode: null
  },
  es_uy: {
    label: "Spanish (Uruguay)",
    countryCode: null
  },
  es_ve: {
    label: "Spanish (Venezuela)",
    countryCode: null
  },
  sw: {
    label: "Swahili",
    countryCode: null
  },
  sv: {
    label: "Swedish",
    countryCode: null
  },
  gsw: {
    label: "Swiss German",
    countryCode: null
  },
  tl: {
    label: "Tagalog",
    countryCode: null
  },
  ta: {
    label: "Tamil",
    countryCode: null
  },
  te: {
    label: "Telugu",
    countryCode: null
  },
  th: {
    label: "Thai",
    countryCode: null
  },
  tr: {
    label: "Turkish",
    countryCode: null
  },
  uk: {
    label: "Ukrainian",
    countryCode: null
  },
  ur: {
    label: "Urdu",
    countryCode: null
  },
  vi: {
    label: "Vietnamese",
    countryCode: null
  },
  zu: {
    label: "Zulu",
    countryCode: null
  }
}

how to fill it

  1. look at English name, find translation at https://www.omniglot.com/language/names.htm , fill own name in 'label' prop
  2. click on the locale own name at this site, you will see detailed article above language and in which country (ies) it's used.
  3. pick up the proper country code from here https://countrycode.org

you could ask @patpedrosa to do it or work on it if you don't have more prioritised tasks
for now I suggest to fill this map with languages we currently support only then merge PR and open a task to fill the whole list

@L03TJ3
Copy link
Collaborator Author

L03TJ3 commented Jun 13, 2024

@decentralauren can you decide if there is still a priority or need for this?

There was a request made to make the languages shown in settings to be translated to their native representation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants