fix(i18n): harden Brazilian Portuguese locale
This commit is contained in:
1 parent
00ba71d4df
commit
9f913055d7
5 files changed
+92
-16
No files matched your search
@@ -4,7 +4,8 @@
|
||||
|
||||
export const LANGS = {
|
||||
en: 'English', de: 'Deutsch', es: 'Español', fr: 'Français', it: 'Italiano',
|
||||
pt: 'Português (Portugal)', 'pt-BR': 'Português (Brasil)', pl: 'Polski', tr: 'Türkçe', ru: 'Русский', zh: '中文',
|
||||
pt: 'Português (Portugal)', 'pt-BR': 'Português (Brasil)', pl: 'Polski',
|
||||
tr: 'Türkçe', ru: 'Русский', zh: '中文',
|
||||
ko: '한국어', hi: 'हिन्दी'
|
||||
}
|
||||
export const INSTR_LANGS = ['en', 'es', 'fr', 'it', 'tr', 'ru', 'zh', 'hi', 'pl', 'ko']
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, test } from 'vitest'
|
||||
import { createHash } from 'node:crypto'
|
||||
import pt from '../locales/pt.js'
|
||||
import ptBR from '../locales/pt-BR.js'
|
||||
import ptBR, { PT_BR_OVERRIDES } from '../locales/pt-BR.js'
|
||||
import { DATE_LOCALES, LANGS } from './i18n-core.js'
|
||||
|
||||
const placeholders = value => [...String(value).matchAll(/\{\d+\}/g)].map(match => match[0]).sort()
|
||||
@@ -12,18 +13,34 @@ describe('Brazilian Portuguese locale', () => {
|
||||
expect(DATE_LOCALES['pt-BR']).toBe('pt-BR')
|
||||
})
|
||||
|
||||
test('has the complete key set and preserves interpolation placeholders', () => {
|
||||
test('matches the source key set and preserves interpolation placeholders', () => {
|
||||
expect(Object.keys(ptBR).sort()).toEqual(Object.keys(pt).sort())
|
||||
for (const [source, translated] of Object.entries(ptBR)) {
|
||||
expect(placeholders(translated), source).toEqual(placeholders(source))
|
||||
}
|
||||
})
|
||||
|
||||
test('does not leak the most visible European Portuguese UI terms', () => {
|
||||
test('makes every inherited pt-PT value an explicit reviewed snapshot', () => {
|
||||
const inherited = Object.entries(pt)
|
||||
.filter(([key]) => !(key in PT_BR_OVERRIDES))
|
||||
.sort(([a], [b]) => a.localeCompare(b))
|
||||
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
|
||||
|
||||
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(222)
|
||||
expect(inherited).toHaveLength(432)
|
||||
expect(fingerprint).toBe('ed0546448785eef2e75ef23523c192f6e19e878b9e920a64a77009c662e731a6')
|
||||
})
|
||||
|
||||
test('does not leak European Portuguese UI terms', () => {
|
||||
const text = Object.values(ptBR).join('\n')
|
||||
expect(text).not.toMatch(/\b(ficheiro\w*|telemóvel\w*|ecrã\w*|regist(?:ar|ado|ada|ados|adas|o|os)|eliminar|definições)\b/i)
|
||||
const europeanPortuguese = /(?:^|[^\p{L}])(?:ficheiro\p{L}*|telemóvel\p{L}*|ecrã\p{L}*|regist(?:o|am|ado|ada|ados|adas)|eliminad\p{L}*|definições|cronómetro|detetad\p{L}*|gémeos|abdómen|anca|coifa dos rotadores|escadora|completaste|acabaste|aguentas|definires|completares|aguenta|aguentaste|ficaste|viajares)(?=$|[^\p{L}])/iu
|
||||
expect(text).not.toMatch(europeanPortuguese)
|
||||
expect(text).not.toMatch(/[«»]/u)
|
||||
expect(ptBR.Save).toBe('Salvar')
|
||||
expect(ptBR.Settings).toBe('Configurações')
|
||||
expect(ptBR['Delete workout']).toBe('Excluir treino')
|
||||
expect(ptBR.Superset).toBe('Superset')
|
||||
expect(ptBR['Guest mode — data lives only in this browser.']).toContain('visitante')
|
||||
expect(ptBR['Sign in with passkey']).toContain('chave de acesso')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user