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