-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f5ccff
commit 10049f1
Showing
90 changed files
with
1,698 additions
and
1,029 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
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 @@ | ||
Bug fixes and performance improvements |
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,25 @@ | ||
# i18n helpers | ||
|
||
Scripts for managing i18n translation keys and YAML files. | ||
|
||
## Features | ||
1. **Extract Missing Translations**: Scans `src/` for `lang('key')` patterns and identifies missing translations in `src/i18n/`. | ||
2. **Update Locales**: Merges new translations from `dev/locales/input.yaml` into YAML files in `src/i18n/`. | ||
|
||
## Usage | ||
|
||
### Extract Missing Translations | ||
1. Run `npm run i18n:findMissing` | ||
|
||
2. Missing keys are written to `output.yaml`. | ||
|
||
### Update Locales | ||
1. Add translations to `dev/locales/input.yaml`: | ||
```yaml | ||
en: | ||
$key: "English text" | ||
de: | ||
$key: "German text" | ||
``` | ||
2. Run `npm run i18n:update` |
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,3 @@ | ||
const i18nDir = './src/i18n'; | ||
|
||
module.exports = { i18nDir }; |
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,79 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const yaml = require('js-yaml'); | ||
const { i18nDir } = require('./config'); | ||
|
||
const outputFilePath = path.resolve(__dirname, 'output.yaml'); | ||
const srcDir = './src'; | ||
|
||
function extractLangKeys(dir) { | ||
const langKeys = new Set(); | ||
|
||
function traverse(directory) { | ||
const files = fs.readdirSync(directory); | ||
|
||
files.forEach((file) => { | ||
const fullPath = path.join(directory, file); | ||
const stat = fs.statSync(fullPath); | ||
|
||
if (stat.isDirectory()) { | ||
traverse(fullPath); | ||
} else if (file.endsWith('.ts') || file.endsWith('.tsx') || file.endsWith('.js') || file.endsWith('.jsx')) { | ||
const content = fs.readFileSync(fullPath, 'utf8'); | ||
|
||
const matches = content.matchAll(/lang\(\s*(['"`])((?:\\.|[^\\])*?)\1(?:,|\))/gs); | ||
|
||
for (const match of matches) { | ||
let key = match[2]; | ||
|
||
key = key.replace(/\\'/g, "'").replace(/\\"/g, '"').replace(/\\n/g, '\n'); | ||
|
||
langKeys.add(key); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
traverse(dir); | ||
return langKeys; | ||
} | ||
|
||
function findMissingTranslations(langKeys, i18nDir) { | ||
const missingTranslations = {}; | ||
|
||
const localeFiles = fs.readdirSync(i18nDir).filter((file) => file.endsWith('.yaml')); | ||
|
||
localeFiles.forEach((file) => { | ||
const lang = path.basename(file, '.yaml'); | ||
const filePath = path.join(i18nDir, file); | ||
const translations = yaml.load(fs.readFileSync(filePath, 'utf8')) || {}; | ||
|
||
langKeys.forEach((key) => { | ||
if (!translations[key]) { | ||
if (!missingTranslations[lang]) { | ||
missingTranslations[lang] = {}; | ||
} | ||
missingTranslations[lang][key] = key; | ||
} | ||
}); | ||
}); | ||
|
||
return missingTranslations; | ||
} | ||
|
||
function writeMissingTranslations(missingTranslations, outputFilePath) { | ||
const yamlContent = yaml.dump(missingTranslations, { noRefs: true, indent: 2 }); | ||
fs.writeFileSync(outputFilePath, yamlContent, 'utf8'); | ||
console.log(`Missing translations written to ${outputFilePath}`); | ||
} | ||
|
||
(function main() { | ||
console.log('Extracting lang keys from source code...'); | ||
const langKeys = extractLangKeys(srcDir); | ||
|
||
console.log('Checking for missing translations...'); | ||
const missingTranslations = findMissingTranslations(langKeys, i18nDir); | ||
|
||
console.log('Writing missing translations to output file...'); | ||
writeMissingTranslations(missingTranslations, outputFilePath); | ||
})(); |
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,46 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const yaml = require('js-yaml'); | ||
const { i18nDir } = require('./config'); | ||
|
||
const inputFilePath = path.resolve(__dirname, 'input.yaml'); | ||
|
||
function updateYamlFiles() { | ||
try { | ||
const inputContent = fs.readFileSync(inputFilePath, 'utf8'); | ||
const inputData = yaml.load(inputContent); | ||
|
||
for (const lang in inputData) { | ||
const langData = inputData[lang]; | ||
const yamlFilePath = path.join(i18nDir, `${lang}.yaml`); | ||
|
||
let existingData = {}; | ||
|
||
if (fs.existsSync(yamlFilePath)) { | ||
const existingContent = fs.readFileSync(yamlFilePath, 'utf8'); | ||
existingData = yaml.load(existingContent) || {}; | ||
} | ||
|
||
const updatedData = { | ||
...existingData, | ||
...langData, | ||
}; | ||
|
||
const updatedYaml = yaml.dump(updatedData, { | ||
noRefs: true, | ||
indent: 2, | ||
lineWidth: -1, | ||
quotingType: '"', | ||
}); | ||
fs.writeFileSync(yamlFilePath, updatedYaml, 'utf8'); | ||
|
||
console.log(`Updated: ${yamlFilePath}`); | ||
} | ||
|
||
console.log('All YAML files have been updated.'); | ||
} catch (error) { | ||
console.error('Error updating YAML files:', error); | ||
} | ||
} | ||
|
||
updateYamlFiles(); |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
index.css | ||
bg | ||
images | ||
common.js | ||
!_common/* |
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,32 @@ | ||
function getPlatform() { | ||
const { | ||
userAgent, | ||
platform, | ||
} = window.navigator; | ||
|
||
const iosPlatforms = ['iPhone', 'iPad', 'iPod']; | ||
if ( | ||
iosPlatforms.indexOf(platform) !== -1 | ||
// For new IPads with M1 chip and IPadOS platform returns "MacIntel" | ||
|| (platform === 'MacIntel' && ('maxTouchPoints' in navigator && navigator.maxTouchPoints > 2)) | ||
) { | ||
return 'iOS'; | ||
} | ||
|
||
const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K']; | ||
if (macosPlatforms.indexOf(platform) !== -1) return 'macOS'; | ||
|
||
const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE']; | ||
if (windowsPlatforms.indexOf(platform) !== -1) return 'Windows'; | ||
|
||
if (/Android/.test(userAgent)) return 'Android'; | ||
|
||
if (/Linux/.test(platform)) return 'Linux'; | ||
|
||
return undefined; | ||
} | ||
|
||
export let platform = getPlatform(); | ||
|
||
export const IS_DESKTOP = ['Windows', 'Linux', 'macOS'].includes(platform); | ||
export const IS_MOBILE = !IS_DESKTOP; |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.