mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-19 05:55:34 +09:00
fix(i18n): review translations and fix i18n library misuse (#2750)
This commit is contained in:
1 parent
78f783f0c4
commit
8cb097f954
575 files changed
+192671
-160540
No files matched your search
@@ -219,9 +219,6 @@ export function setLocale(localeCode: string): void {
|
||||
}
|
||||
const normalized = normalizeLocale(locale.code);
|
||||
const previousLocale = normalizeLocale(getCurrentLocale());
|
||||
if (normalized === previousLocale) {
|
||||
return;
|
||||
}
|
||||
const sequence = ++localeChangeSequence;
|
||||
void (async () => {
|
||||
try {
|
||||
@@ -230,7 +227,7 @@ export function setLocale(localeCode: string): void {
|
||||
logger.error(`Failed to load locale ${localeCode}:`, error);
|
||||
return;
|
||||
}
|
||||
if (sequence !== localeChangeSequence) {
|
||||
if (sequence !== localeChangeSequence || normalized === previousLocale) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {getRegionDisplayName as resolveRegionName} from '@fluxer/geo_utils/src/RegionFormatting';
|
||||
import type {I18n} from '@lingui/core';
|
||||
import type {I18n, MessageDescriptor} from '@lingui/core';
|
||||
import {msg} from '@lingui/core/macro';
|
||||
|
||||
const YOUR_REGION_DESCRIPTOR = msg({
|
||||
@@ -9,15 +9,273 @@ const YOUR_REGION_DESCRIPTOR = msg({
|
||||
comment: 'Short label in the region display names. Keep it concise.',
|
||||
});
|
||||
|
||||
const US_STATE_DESCRIPTORS: Record<string, MessageDescriptor> = {
|
||||
AL: msg({
|
||||
message: 'Alabama',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
AK: msg({
|
||||
message: 'Alaska',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
AZ: msg({
|
||||
message: 'Arizona',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
AR: msg({
|
||||
message: 'Arkansas',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
CA: msg({
|
||||
message: 'California',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
CO: msg({
|
||||
message: 'Colorado',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
CT: msg({
|
||||
message: 'Connecticut',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
DE: msg({
|
||||
message: 'Delaware',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
FL: msg({
|
||||
message: 'Florida',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
GA: msg({
|
||||
message: 'Georgia',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
HI: msg({
|
||||
message: 'Hawaii',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
ID: msg({
|
||||
message: 'Idaho',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
IL: msg({
|
||||
message: 'Illinois',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
IN: msg({
|
||||
message: 'Indiana',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
IA: msg({
|
||||
message: 'Iowa',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
KS: msg({
|
||||
message: 'Kansas',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
KY: msg({
|
||||
message: 'Kentucky',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
LA: msg({
|
||||
message: 'Louisiana',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
ME: msg({
|
||||
message: 'Maine',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
MD: msg({
|
||||
message: 'Maryland',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
MA: msg({
|
||||
message: 'Massachusetts',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
MI: msg({
|
||||
message: 'Michigan',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
MN: msg({
|
||||
message: 'Minnesota',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
MS: msg({
|
||||
message: 'Mississippi',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
MO: msg({
|
||||
message: 'Missouri',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
MT: msg({
|
||||
message: 'Montana',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
NE: msg({
|
||||
message: 'Nebraska',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
NV: msg({
|
||||
message: 'Nevada',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
NH: msg({
|
||||
message: 'New Hampshire',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
NJ: msg({
|
||||
message: 'New Jersey',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
NM: msg({
|
||||
message: 'New Mexico',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
NY: msg({
|
||||
message: 'New York',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
NC: msg({
|
||||
message: 'North Carolina',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
ND: msg({
|
||||
message: 'North Dakota',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
OH: msg({
|
||||
message: 'Ohio',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
OK: msg({
|
||||
message: 'Oklahoma',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
OR: msg({
|
||||
message: 'Oregon',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
PA: msg({
|
||||
message: 'Pennsylvania',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
RI: msg({
|
||||
message: 'Rhode Island',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
SC: msg({
|
||||
message: 'South Carolina',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
SD: msg({
|
||||
message: 'South Dakota',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
TN: msg({
|
||||
message: 'Tennessee',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
TX: msg({
|
||||
message: 'Texas',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
UT: msg({
|
||||
message: 'Utah',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
VT: msg({
|
||||
message: 'Vermont',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
VA: msg({
|
||||
message: 'Virginia',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
WA: msg({
|
||||
message: 'Washington',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
WV: msg({
|
||||
message: 'West Virginia',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
WI: msg({
|
||||
message: 'Wisconsin',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
WY: msg({
|
||||
message: 'Wyoming',
|
||||
context: 'us-state',
|
||||
comment: 'US state name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
DC: msg({
|
||||
message: 'District of Columbia',
|
||||
context: 'us-state',
|
||||
comment: 'US federal district name, shown next to the country name in the mature content gate.',
|
||||
}),
|
||||
};
|
||||
|
||||
export function getRegionDisplayName(i18n: I18n, countryCode?: string, regionCode?: string): string {
|
||||
if (!countryCode) {
|
||||
return i18n._(YOUR_REGION_DESCRIPTOR);
|
||||
}
|
||||
try {
|
||||
const countryName = resolveRegionName(countryCode, {locale: 'en'});
|
||||
const countryName = resolveRegionName(countryCode, {locale: i18n.locale});
|
||||
if (countryCode === 'US' && regionCode) {
|
||||
try {
|
||||
const stateName = getUSStateName(regionCode);
|
||||
const stateName = getUSStateName(i18n, regionCode);
|
||||
return `${stateName}, ${countryName || 'United States'}`;
|
||||
} catch {
|
||||
return countryName || countryCode;
|
||||
@@ -29,59 +287,7 @@ export function getRegionDisplayName(i18n: I18n, countryCode?: string, regionCod
|
||||
}
|
||||
}
|
||||
|
||||
const getUSStateName = (stateCode: string): string => {
|
||||
const states: Record<string, string> = {
|
||||
AL: 'Alabama',
|
||||
AK: 'Alaska',
|
||||
AZ: 'Arizona',
|
||||
AR: 'Arkansas',
|
||||
CA: 'California',
|
||||
CO: 'Colorado',
|
||||
CT: 'Connecticut',
|
||||
DE: 'Delaware',
|
||||
FL: 'Florida',
|
||||
GA: 'Georgia',
|
||||
HI: 'Hawaii',
|
||||
ID: 'Idaho',
|
||||
IL: 'Illinois',
|
||||
IN: 'Indiana',
|
||||
IA: 'Iowa',
|
||||
KS: 'Kansas',
|
||||
KY: 'Kentucky',
|
||||
LA: 'Louisiana',
|
||||
ME: 'Maine',
|
||||
MD: 'Maryland',
|
||||
MA: 'Massachusetts',
|
||||
MI: 'Michigan',
|
||||
MN: 'Minnesota',
|
||||
MS: 'Mississippi',
|
||||
MO: 'Missouri',
|
||||
MT: 'Montana',
|
||||
NE: 'Nebraska',
|
||||
NV: 'Nevada',
|
||||
NH: 'New Hampshire',
|
||||
NJ: 'New Jersey',
|
||||
NM: 'New Mexico',
|
||||
NY: 'New York',
|
||||
NC: 'North Carolina',
|
||||
ND: 'North Dakota',
|
||||
OH: 'Ohio',
|
||||
OK: 'Oklahoma',
|
||||
OR: 'Oregon',
|
||||
PA: 'Pennsylvania',
|
||||
RI: 'Rhode Island',
|
||||
SC: 'South Carolina',
|
||||
SD: 'South Dakota',
|
||||
TN: 'Tennessee',
|
||||
TX: 'Texas',
|
||||
UT: 'Utah',
|
||||
VT: 'Vermont',
|
||||
VA: 'Virginia',
|
||||
WA: 'Washington',
|
||||
WV: 'West Virginia',
|
||||
WI: 'Wisconsin',
|
||||
WY: 'Wyoming',
|
||||
DC: 'District of Columbia',
|
||||
};
|
||||
return states[stateCode] || stateCode;
|
||||
const getUSStateName = (i18n: I18n, stateCode: string): string => {
|
||||
const descriptor = US_STATE_DESCRIPTORS[stateCode];
|
||||
return descriptor ? i18n._(descriptor) : stateCode;
|
||||
};
|
||||
Reference in new issue
Block a user