-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update pt.json and create internationalization controller
- Loading branch information
1 parent
425c4d1
commit a2fce77
Showing
7 changed files
with
105 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* eslint-disable no-console */ | ||
const sourceFile = "en"; | ||
const targetFile = "pt"; | ||
|
||
const srcFile = require(`./src/locales/${sourceFile}/${sourceFile}.json`); | ||
const tgtFile = require(`./src/locales/${targetFile}/${targetFile}.json`); | ||
|
||
// rest of the code... | ||
|
||
function findMissingTranslations(sourceMap, targetMap, prefix = "") { | ||
let missingKeys = []; | ||
|
||
Object.keys(sourceMap).forEach((key) => { | ||
if (typeof sourceMap[key] === "object") { | ||
missingKeys = [ | ||
...missingKeys, | ||
...findMissingTranslations( | ||
sourceMap[key], | ||
targetMap[key] || {}, | ||
`${prefix}${key}.`, | ||
), | ||
]; | ||
} else if (!(key in (targetMap || {}))) { | ||
missingKeys.push(`${prefix}${key}`); | ||
} | ||
}); | ||
|
||
return missingKeys; | ||
} | ||
|
||
const missingTranslations = findMissingTranslations(srcFile, tgtFile); | ||
|
||
console.log( | ||
missingTranslations.length | ||
? missingTranslations | ||
: ` No missing translations between "${sourceFile}" lang and "${targetFile}" lang`, | ||
); | ||
|
||
// The script will output the missing translations in the console. | ||
// If there are no missing translations, the output will be an empty array. | ||
|
||
/** | ||
* [ | ||
'HomeLayout.Opengraph title', | ||
'HomeLayout.Opengraph description', | ||
'About.About_Page', | ||
'About.About_Page_Description', | ||
'Info.Info_Page', | ||
'PrivacyPolices.Privacy Policy', | ||
'Terms.Terms and Conditions of Multiform Validator library', | ||
'DocumentationJsFunctions.Import', | ||
'DocumentationJsFunctions.require', | ||
'DocumentationJsFunctions.(optional boolean) - If set to', | ||
'DocumentationJsFunctions.trim()' | ||
] | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// locales/client.ts | ||
"use client"; | ||
import { createI18nClient } from "next-international/client"; | ||
|
||
export const { useI18n, useScopedI18n, I18nProviderClient } = createI18nClient({ | ||
en: () => import("./en/en.json"), | ||
pt: () => import("./pt/pt.json"), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// locales/server.ts | ||
import { createI18nServer } from "next-international/server"; | ||
|
||
export const { getI18n, getScopedI18n, getStaticParams } = createI18nServer({ | ||
en: () => import("./en/en.json"), | ||
pt: () => import("./pt/pt.json"), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters