0

First of all let me say I don't know much about the subject, so I may inadvertently be a bit blunt.

I'm trying to extract language and country from the locale code, in order to create custom form for my clients.

List of locales from : List of All Locales and Their Short Codes?

My code so far :

# Unless specified, simplified chinese for RPC and Singapour, traditional for HK and Macao SAR, ROC
# zh = simplified, ch = traditional
match locale:
    case "zh_CN", "zh_SG":
        language = "ch"
        country = locale[3:]
    case "zh_Hans":
        language = "zh"
        country = "CN"
    case 'zh_Hans_CN', 'zh_Hans_HK', 'zh_Hans_MO', 'zh_Hans_SG':
        language = "zh"
        country = locale[8:]
    case "zh_Hant":
        language = "ch"
        country = "CN"
    case 'zh_Hant_HK', 'zh_Hant_MO', 'zh_Hant_TW':
        language = "ch"
        country = locale[8:]

Is this acceptable ?

geriwald
  • 190
  • 1
  • 4
  • 17
  • note: locale string can be much more complex, so I would decompose the locale string, and check: I have language: ok. I have country: ok (the second two letter code), else guess from the script tipe. And you may get more parts, just ignore the parts that are not two letter longs – Giacomo Catenazzi Sep 22 '22 at 13:35

0 Answers0