|
| 1 | +module Fastlane |
| 2 | + # Defines a single Locale with the various locale codes depending on the representation needed. |
| 3 | + # |
| 4 | + # The various locale codes formats for the various keys can be found as follows: |
| 5 | + # |
| 6 | + # - glotpress: |
| 7 | + # Go to the GP project page (e.g. https://translate.wordpress.org/projects/apps/android/dev/) |
| 8 | + # and hover over the link for each locale, locale code is in the URL. |
| 9 | + # - android: (`values-*` folder names) |
| 10 | + # See https://developer.android.com/guide/topics/resources/providing-resources#AlternativeResources (Scroll to Table 2) |
| 11 | + # [ISO639-1 (lowercase)]-r[ISO-3166-alpha-2 (uppercase)], e.g. `zh-rCN` ("Chinese understood in mainland China") |
| 12 | + # - google_play: (PlayStore Console, for metadata, release_notes.xml and `fastlane supply`) |
| 13 | + # See https://support.google.com/googleplay/android-developer/answer/9844778 (then open "View list of available languages"). |
| 14 | + # See also https://github.com/fastlane/fastlane/blob/master/supply/lib/supply/languages.rb |
| 15 | + # - ios: (`*.lproj`) |
| 16 | + # See https://developer.apple.com/documentation/xcode/choosing-localization-regions-and-scripts#Understand-the-Language-Identifier |
| 17 | + # [ISO639-1/ISO639-2 (lowercase)]-[ISO 3166-1 (uppercase region or titlecase script)], e.g. `zh-Hans` ("Simplified Chinese" script) |
| 18 | + # - app_store: (AppStoreConnect, for metadata and `fastlane deliver`) |
| 19 | + # See https://github.com/fastlane/fastlane/blob/master/deliver/lib/deliver/languages.rb |
| 20 | + # |
| 21 | + # Links to ISO Standards |
| 22 | + # ISO standard portal: https://www.iso.org/obp/ui/#search |
| 23 | + # ISO 639-1: https://www.loc.gov/standards/iso639-2/php/code_list.php |
| 24 | + # ISO-3166-alpha2: https://www.iso.org/obp/ui/#iso:pub:PUB500001:en |
| 25 | + # |
| 26 | + # Notes about region vs script codes in ISO-3166-1 |
| 27 | + # `zh-CN` is a locale code - Chinese understood in mainland China |
| 28 | + # `zh-Hans` is a language+script code - Chinese written in Simplified Chinese (not just understood in mainland China) |
| 29 | + # |
| 30 | + Locale = Struct.new(:glotpress, :android, :google_play, :ios, :app_store, keyword_init: true) do |
| 31 | + # Returns the Locale with the given glotpress locale code from the list of all known locales (`Locales.all`) |
| 32 | + # |
| 33 | + # @param [String] The glotpress locale code for the locale to fetch |
| 34 | + # @return [Locale] The locale found |
| 35 | + # @raise [RuntimeException] if the locale with given glotpress code is unknown |
| 36 | + def self.[](code) |
| 37 | + Locales[code].first |
| 38 | + end |
| 39 | + end |
| 40 | +end |
0 commit comments