-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feat/profiles
- Loading branch information
Showing
31 changed files
with
342 additions
and
114 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
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
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,112 @@ | ||
import { execSync } from 'child_process'; | ||
import * as fs from 'fs'; | ||
|
||
const changes: { | ||
[file: string]: { | ||
[key: string]: { | ||
[language: string]: { | ||
oldValue?: string; | ||
newValue?: string; | ||
}; | ||
}; | ||
}; | ||
} = {}; | ||
|
||
function run() { | ||
const fileChanges = execSync('git diff -U200000 --no-prefix release..release-candidate public/locales') | ||
.toString() | ||
.split('\n') | ||
.filter((s) => !!s) | ||
.map((s) => s.trim()); | ||
|
||
let filename = ''; | ||
let language = ''; | ||
let path: string[] = []; | ||
|
||
for (const line of fileChanges) { | ||
if (line.startsWith('diff --git')) { | ||
[filename, language] = line.split('\n')[0].split('/').reverse() || []; | ||
path = []; | ||
} else if (line.startsWith('"') && line.endsWith('{')) { | ||
// This is the start of a new subgroup, parse the name and add it to the path | ||
path.push(line.split(':')[0].replace(/"/g, '')); | ||
} else if (line.startsWith('}')) { | ||
// This is the end of a subgroup, so take last path segment away | ||
path.pop(); | ||
} else if (line.startsWith('---') || line.startsWith('+++')) { | ||
// Skip these lines | ||
} else if (line.startsWith('+') || line.startsWith('-')) { | ||
// This is a changed line, first parse the value | ||
// using regex to strip the leading +/-, whitespace, and quotes OR trailing quote and comma | ||
// Then split on the colon and middle quotes | ||
const [name, value] = line.replace(/(^[+-]\s*")|(",$)/g, '').split('": "'); | ||
|
||
// Reconstruct the full path from any parent paths | ||
const key = [...path, name].join('.'); | ||
|
||
// Make sure that the nested items have values | ||
changes[filename] ||= {}; | ||
changes[filename][key] ||= {}; | ||
changes[filename][key][language] ||= {}; | ||
|
||
// Set the old or new value props based on the git symbol | ||
if (line.startsWith('+')) { | ||
changes[filename][key][language].newValue = value; | ||
} else { | ||
changes[filename][key][language].oldValue = value; | ||
} | ||
} | ||
} | ||
|
||
const languageGroups: { | ||
[language: string]: string[]; | ||
} = {}; | ||
|
||
Object.entries(changes).forEach(([filename, fileChanges]) => { | ||
Object.entries(fileChanges).forEach(([key, languages]) => { | ||
Object.entries(languages).forEach(([language, props]) => { | ||
// Only include keys with updated new values or where the English has updated new values | ||
if (languages['en'].newValue !== undefined || props.newValue !== undefined) { | ||
// Add the headers | ||
languageGroups[language] ||= [ | ||
[ | ||
'File', | ||
'Translation Key', | ||
// Show Old/New English fields for other languages to help translators | ||
...(language === 'en' ? [] : ['Original Value (en)', 'New Value (en)']), | ||
`Original Value (${language})`, | ||
`Updated Value (${language})`, | ||
].join(','), | ||
]; | ||
|
||
languageGroups[language].push( | ||
[ | ||
filename, | ||
key, | ||
// Show Old/New English values for other languages to help translators | ||
...(language === 'en' ? [] : [languages['en']?.oldValue || '', languages['en']?.newValue || '']), | ||
props.oldValue || '', | ||
props.newValue || '', | ||
] | ||
// Wrap with quotes to escape any internal commas | ||
.map((v) => `"${v}"`) | ||
.join(','), | ||
); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
if (!fs.existsSync('.temp-translations')) { | ||
fs.mkdirSync('.temp-translations'); | ||
} | ||
|
||
Object.entries(languageGroups).forEach(([language, values]) => { | ||
const file = `.temp-translations/translations.${language}.csv`; | ||
|
||
fs.writeFileSync(file, values.join('\n'), 'utf8'); | ||
console.info(`Wrote ${values.length - 1} keys to ${file}`); | ||
}); | ||
} | ||
|
||
run(); |
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,9 @@ | ||
{ | ||
"include": ["./**/*"], | ||
"compilerOptions": { | ||
"module": "NodeNext", | ||
"types": [ | ||
"node" | ||
] | ||
}, | ||
} |
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,60 @@ | ||
import * as fs from 'fs'; | ||
|
||
// @ts-ignore | ||
import { ColumnOption, parse } from 'csv-parse/sync'; | ||
|
||
interface Line { | ||
filename: string; | ||
key: string; | ||
value: string; | ||
} | ||
|
||
interface JsonObject { | ||
[key: string]: string | JsonObject; | ||
} | ||
|
||
function updateObject(obj: JsonObject, paths: string[], newValue: string) { | ||
const key = paths.shift() || ''; | ||
|
||
if (paths.length <= 0) { | ||
obj[key] = newValue; | ||
} else { | ||
obj[key] = updateObject(obj[key] as JsonObject, paths, newValue); | ||
} | ||
|
||
return obj; | ||
} | ||
|
||
function run() { | ||
const allFiles = fs.readdirSync('.temp-translations'); | ||
|
||
for (const file of allFiles) { | ||
const language = file.split('.')[1]; | ||
|
||
const lines = parse(fs.readFileSync(`.temp-translations/${file}`), { | ||
fromLine: 2, | ||
columns: ['filename', 'key', ...(language === 'en' ? [] : [false as ColumnOption, false as ColumnOption]), false, 'value'], | ||
relax_column_count: true, | ||
}) as Line[]; | ||
const groups = lines.reduce((allGroups, line) => { | ||
allGroups[line.filename] ||= []; | ||
allGroups[line.filename].push(line); | ||
|
||
return allGroups; | ||
}, {} as { [filename: string]: Line[] }); | ||
|
||
Object.entries(groups).forEach(([jsonFile, lines]) => { | ||
const filename = `public/locales/${language}/${jsonFile}`; | ||
|
||
const json = JSON.parse(fs.readFileSync(filename).toString()); | ||
|
||
for (const line of lines) { | ||
updateObject(json, line.key.split('.'), line.value); | ||
} | ||
|
||
fs.writeFileSync(filename, JSON.stringify(json)); | ||
}); | ||
} | ||
} | ||
|
||
run(); |
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
Oops, something went wrong.