mirror of
https://github.com/Afilmory/afilmory
synced 2026-04-24 23:05:05 +00:00
- Added i18next and react-i18next for multi-language support in the application. - Created localization files for English, Japanese, Korean, Traditional Chinese, and Simplified Chinese. - Implemented translation hooks in various components to replace hardcoded strings with translatable keys. - Updated ESLint configuration to include new i18n JSON validation rules. - Introduced a new event bus for handling i18n updates during development. Signed-off-by: Innei <tukon479@gmail.com>
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
import { cleanJsonText, sortObjectKeys } from './utils.js'
|
|
|
|
/**
|
|
* @type {import("eslint").ESLint.Plugin}
|
|
*/
|
|
export default {
|
|
rules: {
|
|
'recursive-sort': {
|
|
meta: {
|
|
type: 'layout',
|
|
fixable: 'code',
|
|
},
|
|
create(context) {
|
|
return {
|
|
Program(node) {
|
|
if (context.filename.endsWith('.json')) {
|
|
const { sourceCode } = context
|
|
const text = cleanJsonText(sourceCode.getText())
|
|
|
|
try {
|
|
const json = JSON.parse(text)
|
|
const sortedJson = sortObjectKeys(json)
|
|
const sortedText = `${JSON.stringify(sortedJson, null, 2)}\n`
|
|
|
|
const noWhiteSpaceDiff = (a, b) =>
|
|
a.replaceAll(/\s/g, '') === b.replaceAll(/\s/g, '')
|
|
|
|
if (!noWhiteSpaceDiff(text, sortedText)) {
|
|
context.report({
|
|
node,
|
|
message: 'JSON keys are not sorted recursively',
|
|
fix(fixer) {
|
|
return fixer.replaceText(node, sortedText)
|
|
},
|
|
})
|
|
}
|
|
} catch (error) {
|
|
context.report({
|
|
node,
|
|
message: `Invalid JSON: ${error.message}`,
|
|
})
|
|
}
|
|
}
|
|
},
|
|
}
|
|
},
|
|
},
|
|
},
|
|
}
|