Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ptBR (Brazilian Portuguese) in translations #10188

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/admin/dashboard/src/i18n/languages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { de, enUS, pl, tr } from "date-fns/locale"
import { de, enUS, pl, ptBR, tr } from "date-fns/locale"
import { Language } from "./types"

export const languages: Language[] = [
Expand All @@ -20,6 +20,12 @@ export const languages: Language[] = [
ltr: true,
date_locale: pl,
},
{
code: "ptBR",
display_name: "Português (Brasil)",
ltr: true,
date_locale: ptBR,
},
{
code: "tr",
display_name: "Türkçe",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from "fs"
import path from "path"
import { describe, expect, test } from "vitest"
import { languages } from "../../languages.ts"

import schema from "../$schema.json"

Expand Down Expand Up @@ -38,29 +39,36 @@ function getTranslationKeys(obj: any, prefix = ""): string[] {
return keys.sort()
}

describe("translation schema validation", () => {
test("en.json should have all keys defined in schema", () => {
const enPath = path.join(translationsDir, "en.json")
const enTranslations = JSON.parse(fs.readFileSync(enPath, "utf-8"))
function validateTranslationFile(fileName: string) {
DanSilva41 marked this conversation as resolved.
Show resolved Hide resolved
const filePath = path.join(translationsDir, fileName)
const translations = JSON.parse(fs.readFileSync(filePath, "utf-8"))

const schemaKeys = getRequiredKeysFromSchema(schema)
const translationKeys = getTranslationKeys(enTranslations)
const schemaKeys = getRequiredKeysFromSchema(schema)
const translationKeys = getTranslationKeys(translations)

const missingInTranslations = schemaKeys.filter(
(key) => !translationKeys.includes(key)
)
const extraInTranslations = translationKeys.filter(
(key) => !schemaKeys.includes(key)
)
const missingInTranslations = schemaKeys.filter(
(key) => !translationKeys.includes(key)
)
const extraInTranslations = translationKeys.filter(
(key) => !schemaKeys.includes(key)
)

if (missingInTranslations.length > 0) {
console.error("\nMissing keys in en.json:", missingInTranslations)
}
if (extraInTranslations.length > 0) {
console.error("\nExtra keys in en.json:", extraInTranslations)
}
if (missingInTranslations.length > 0) {
console.error(`\nMissing keys in ${fileName}:`, missingInTranslations)
}
if (extraInTranslations.length > 0) {
console.error(`\nExtra keys in ${fileName}:`, extraInTranslations)
}

expect(missingInTranslations).toEqual([])
expect(extraInTranslations).toEqual([])
expect(missingInTranslations).toEqual([])
expect(extraInTranslations).toEqual([])
}

describe("translation schema validation", () => {
languages.forEach((language) => {
const codeLanguage: string = language.code
test(`${codeLanguage}.json should have all keys defined in schema`, () => {
validateTranslationFile(`${codeLanguage}.json`)
})
})
})
4 changes: 4 additions & 0 deletions packages/admin/dashboard/src/i18n/translations/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import de from "./de.json"
import en from "./en.json"
import pl from "./pl.json"
import ptBR from "./ptBR.json"
import tr from "./tr.json"

export default {
Expand All @@ -13,6 +14,9 @@ export default {
pl: {
translation: pl,
},
ptBR: {
translation: ptBR,
},
tr: {
translation: tr,
},
Expand Down
Loading
Loading