Skip to content

Commit

Permalink
[frontend] add i18n checker
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumejparis committed Sep 11, 2024
1 parent c55afe3 commit 12164aa
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
10 changes: 5 additions & 5 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ steps:
- name: frontend-tests
image: node:20-alpine
volumes:
- name: cache-node-frontend
path: /drone/src/openbas-front/node_modules
- name: cache-node-frontend
path: /drone/src/openbas-front/node_modules
commands:
- cd openbas-front
- yarn install
- yarn build
- yarn check-ts
- yarn lint
# - yarn i18n-checker
- yarn i18n-checker
- NODE_OPTIONS=--max_old_space_size=8192 yarn test

- name: app-e2e
Expand Down Expand Up @@ -66,8 +66,8 @@ steps:
- name: frontend-e2e-tests
image: node:20.16.0
volumes:
- name: cache-node-frontend-e2e
path: /drone/src/openbas-front/node_modules
- name: cache-node-frontend-e2e
path: /drone/src/openbas-front/node_modules
commands:
- apt update
- apt -y install netcat-traditional
Expand Down
16 changes: 11 additions & 5 deletions openbas-front/i18n-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const checkLanguageSupport = (lang) => {
const match = (filePath) => {
try {
const data = fs.readFileSync(filePath, { encoding: 'utf8' });
const regexp = /t\('([\w\s]+)'\)/g;
const regexp = /(?<![a-zA-Z])t\('([\w\s]+)'\)/g;
const matches = [...data.matchAll(regexp)];
matches.forEach((m) => {
const regexWithQuote = `'${m[1]}':`;
Expand Down Expand Up @@ -57,16 +57,22 @@ const checkLanguageSupport = (lang) => {

const run = () => {
const languages = ['fr', 'zh'];
const _missingKeys = {};
const missingKeys = {};

languages.forEach((lang) => {
const keys = checkLanguageSupport(lang);
if (keys.length > 0) {
_missingKeys[lang] = keys;
missingKeys[lang] = keys;
}
});

return _missingKeys;
if (Object.keys(missingKeys).length) {
// eslint-disable-next-line no-console
console.error('Missing keys :', missingKeys);
process.exit(1);
} else {
process.exit(0);
}
};

const _missingKeys = run();
run();
27 changes: 27 additions & 0 deletions openbas-front/src/utils/Localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,14 @@ const i18n = {
here: 'ici',
'This scenario has never run, schedule or run it now!': 'Ce scénario n\'a jamais été exécuté, planifiez-le ou exécutez-le maintenant !',
'Something went wrong. Please refresh the page or try again later.': 'Une erreur s\'est produite. Veuillez actualiser la page ou réessayer plus tard.',
'Targeting Players only': 'Cibler uniquement les joueurs',
'Test Details': 'Détails du test',
Tests: 'Tests',
Warning: 'Avertissement',
'Launch simulation now': 'Lancer la simulation maintenant',
'Launch now': 'Lancer maintenant',
'All teams value': 'Valeur de toutes les équipes',
'not starts with': 'ne commence pas par',
},
zh: {
'Email address': 'email地址',
Expand Down Expand Up @@ -2563,6 +2571,25 @@ const i18n = {
here: '此处',
'This scenario has never run, schedule or run it now!': '此场景从未运行,立即安排或运行它吧!',
'Something went wrong. Please refresh the page or try again later.': '发生错误。请刷新页面或稍后再试。',
'Unknown result': '未知结果',
'Validation type': '验证类型',
'Targeting Players only': '仅定位玩家',
'This expectation is handled automatically by the platform and triggered when target reads the articles': '该预期由平台自动处理,并在目标阅读文章时触发',
'This expectation is handled automatically by the platform and triggered when the target completes the challenges': '该预期由平台自动处理,并在目标完成挑战时触发',
'An isolated player is considered as a group of one player': '一个孤立的玩家被视为一个人的小组',
'its dedicated page': '其专用页面',
'Only SMS and emails related injects will be tested': '仅测试与短信和电子邮件相关的注入',
'Test Details': '测试详情',
'Replay test': '重放测试',
'Delete test': '删除测试',
'Replay all the tests': '重放所有测试',
Tests: '测试',
Warning: '警告',
'Launch simulation now': '立即启动模拟',
'Launch now': '立即启动',
'All teams value': '所有团队的值',
'The score set for the team will also be applied to all players in the team': '为团队设置的分数也将应用于团队中的所有玩家',
Player: '玩家',
},
en: {
openbas_email: 'Email',
Expand Down

0 comments on commit 12164aa

Please sign in to comment.