Skip to content

Commit

Permalink
fix(admin-ui): Fix bad locale detection regex
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Sep 18, 2024
1 parent 801980e commit f336d7f
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ export abstract class LocaleBasePipe implements OnDestroy, PipeTransform {
* is valid for the Intl API.
*/
protected getActiveLocale(localeOverride?: unknown): string {
const locale = typeof localeOverride === 'string' ? localeOverride : this.locale ?? 'en';
const locale = typeof localeOverride === 'string' ? localeOverride : (this.locale ?? 'en');
const hyphenated = locale?.replace(/_/g, '-');

// Check for a double-region string, containing 2 region codes like
// pt-BR-BR, which is invalid. In this case, the second region is used
// and the first region discarded. This would only ever be an issue for
// those languages where the translation file itself encodes the region,
// as in pt_BR & pt_PT.
const matches = hyphenated?.match(/^([a-zA-Z_-]+)(-[A-Z][A-Z])(-[A-Z][A-z])$/);
const matches = hyphenated?.match(/^([a-zA-Z_-]+)(-[A-Z][A-Z])(-[A-Z][A-Z])$/);
if (matches?.length) {
const overriddenLocale = matches[1] + matches[3];
return overriddenLocale;
Expand Down

0 comments on commit f336d7f

Please sign in to comment.