mirror of
https://github.com/mastodon/mastodon.git
synced 2024-08-20 21:08:15 -07:00
Unify array structure for locales
This commit is contained in:
parent
1df1e23644
commit
a1414f0041
4 changed files with 18 additions and 21 deletions
|
@ -221,23 +221,23 @@ module LanguagesHelper
|
|||
# but for presenting posting and filtering languages, we drop the country code and
|
||||
# fall back to the language code, thus skipping these locales there.
|
||||
UI_ONLY_REGIONAL_LOCALES = {
|
||||
'en-GB': 'English (British)',
|
||||
'es-AR': 'Español (Argentina)',
|
||||
'es-MX': 'Español (México)',
|
||||
'fr-CA': 'Français (Canadien)',
|
||||
'pt-BR': 'Português (Brasil)',
|
||||
'pt-PT': 'Português (Portugal)',
|
||||
'sr-Latn': 'Srpski (latinica)',
|
||||
'en-GB': ['English (British)', 'English (British)'].freeze,
|
||||
'es-AR': ['Spanish (Argentina)', 'Español (Argentina)'].freeze,
|
||||
'es-MX': ['Spanish (Mexico)', 'Español (México)'].freeze,
|
||||
'fr-CA': ['French (Canadian)', 'Français (Canadien)'].freeze,
|
||||
'pt-BR': ['Portuguese (Brasil)', 'Português (Brasil)'].freeze,
|
||||
'pt-PT': ['Portuguese (Portugal)', 'Português (Portugal)'].freeze,
|
||||
'sr-Latn': ['Serbian (Latin)', 'Srpski (latinica)'].freeze,
|
||||
}.freeze
|
||||
|
||||
KNOWN_LOCALES = {}.merge(SUPPORTED_LOCALES).merge(UI_ONLY_REGIONAL_LOCALES).freeze
|
||||
|
||||
# Helper for self.sorted_locale_keys
|
||||
private_class_method def self.locale_name_for_sorting(locale)
|
||||
if locale.blank? || locale == 'und'
|
||||
'000'
|
||||
elsif (supported_locale = SUPPORTED_LOCALES[locale.to_sym])
|
||||
ASCIIFolding.new.fold(supported_locale[1]).downcase
|
||||
elsif (regional_locale = UI_ONLY_REGIONAL_LOCALES[locale.to_sym])
|
||||
ASCIIFolding.new.fold(regional_locale).downcase
|
||||
elsif (known_locale = KNOWN_LOCALES[locale.to_sym])
|
||||
ASCIIFolding.new.fold(known_locale[1]).downcase
|
||||
else
|
||||
locale
|
||||
end
|
||||
|
@ -251,10 +251,8 @@ module LanguagesHelper
|
|||
def native_locale_name(locale)
|
||||
if locale.blank? || locale == 'und'
|
||||
I18n.t('generic.none')
|
||||
elsif (supported_locale = SUPPORTED_LOCALES[locale.to_sym])
|
||||
supported_locale[1]
|
||||
elsif (regional_locale = UI_ONLY_REGIONAL_LOCALES[locale.to_sym])
|
||||
regional_locale
|
||||
elsif (known_locale = KNOWN_LOCALES[locale.to_sym])
|
||||
known_locale[1]
|
||||
else
|
||||
locale
|
||||
end
|
||||
|
@ -263,8 +261,8 @@ module LanguagesHelper
|
|||
def standard_locale_name(locale)
|
||||
if locale.blank?
|
||||
I18n.t('generic.none')
|
||||
elsif (supported_locale = SUPPORTED_LOCALES[locale.to_sym])
|
||||
supported_locale[0]
|
||||
elsif (known_locale = KNOWN_LOCALES[locale.to_sym])
|
||||
known_locale[0]
|
||||
else
|
||||
locale
|
||||
end
|
||||
|
|
|
@ -14,8 +14,7 @@ module ActivityPub::CaseTransform
|
|||
when String
|
||||
camel_lower_cache[value] ||= if value.start_with?('_:')
|
||||
"_:#{value.delete_prefix('_:').underscore.camelize(:lower)}"
|
||||
elsif LanguagesHelper::SUPPORTED_LOCALES.key?(value.to_sym) ||
|
||||
LanguagesHelper::UI_ONLY_REGIONAL_LOCALES.key?(value.to_sym)
|
||||
elsif LanguagesHelper::KNOWN_LOCALES.key?(value.to_sym)
|
||||
value
|
||||
else
|
||||
value.underscore.camelize(:lower)
|
||||
|
|
|
@ -96,7 +96,7 @@ namespace :repo do
|
|||
end.uniq.compact
|
||||
|
||||
missing_available_locales = locales_in_files - I18n.available_locales
|
||||
supported_locale_codes = Set.new(LanguagesHelper::SUPPORTED_LOCALES.keys + LanguagesHelper::UI_ONLY_REGIONAL_LOCALES.keys)
|
||||
supported_locale_codes = Set.new(LanguagesHelper::KNOWN_LOCALES.keys)
|
||||
missing_locale_names = I18n.available_locales.reject { |locale| supported_locale_codes.include?(locale) }
|
||||
|
||||
critical = false
|
||||
|
|
|
@ -5,7 +5,7 @@ require 'rails_helper'
|
|||
describe LanguagesHelper do
|
||||
describe 'the SUPPORTED_LOCALES constant' do
|
||||
it 'includes all i18n locales' do
|
||||
expect(Set.new(described_class::SUPPORTED_LOCALES.keys + described_class::UI_ONLY_REGIONAL_LOCALES.keys)).to include(*I18n.available_locales)
|
||||
expect(Set.new(described_class::KNOWN_LOCALES.keys)).to include(*I18n.available_locales)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue