mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-13 21:53:43 +01:00
Merge pull request #11087 from overleaf/jpa-sort-locales
[web] sort all the locale files and check sorting in CI GitOrigin-RevId: 5921e24f22e2ca126f7d49a1956b44d810b52dcd
This commit is contained in:
@@ -37,7 +37,11 @@ async function run() {
|
||||
|
||||
await fs.writeFile(
|
||||
path.join(__dirname, `/../../locales/${code}.json`),
|
||||
JSON.stringify(lang.translation, null, 2) + '\n'
|
||||
JSON.stringify(
|
||||
lang.translation,
|
||||
Object.keys(lang.translation).sort(),
|
||||
2
|
||||
) + '\n'
|
||||
)
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
const fs = require('fs')
|
||||
const Path = require('path')
|
||||
|
||||
const LOCALES = Path.join(__dirname, '../../locales')
|
||||
const CHECK = process.argv.includes('--check')
|
||||
|
||||
async function main() {
|
||||
for (const locale of await fs.promises.readdir(LOCALES)) {
|
||||
if (locale === 'README.md') continue
|
||||
const path = Path.join(LOCALES, locale)
|
||||
const input = await fs.promises.readFile(path, 'utf-8')
|
||||
const parsed = JSON.parse(input)
|
||||
const sorted = JSON.stringify(parsed, Object.keys(parsed).sort(), 2) + '\n'
|
||||
if (input === sorted) {
|
||||
continue
|
||||
}
|
||||
if (CHECK) {
|
||||
console.warn('---')
|
||||
console.warn(
|
||||
locale,
|
||||
'is not sorted. Try running:\n\n',
|
||||
' web$ make sort_locales',
|
||||
'\n'
|
||||
)
|
||||
console.warn('---')
|
||||
throw new Error(locale + ' is not sorted')
|
||||
}
|
||||
console.log('Storing sorted version of', locale)
|
||||
await fs.promises.writeFile(path, sorted)
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(error => {
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
})
|
||||
Reference in New Issue
Block a user