Last task #20 Internationalisation

Add a script to look for missing entries in the different 'locales' directory files (english locale file is use as a default one, its entries are the default ones)

_______________________________________

Ajout d'un script pour rechercher les clés manquantes dans les différents fichiers du dossier 'locales' (le fichier anglais est utilisé par défaut, ses clés sont les clés par défaut)
parent 3ca930bc
Pipeline #5569 passed with stage
in 4 minutes and 48 seconds
var fs = require('fs');
function browseLocalesDirectory()
{
return fs.readdirSync('src/locales');
}
function getLocalesFiles(directoryFiles)
{
// Get content of every file of the 'locales' directory
let translationsFiles = [];
for(let i=0; i<directoryFiles.length; ++i)
{
translationsFiles.push(fs.readFileSync('src/locales/'+directoryFiles[i], { encoding: 'utf8' }));
if(directoryFiles[i]=='en.ts')
{
translationsFiles.unshift(translationsFiles.pop());
directoryFiles.unshift(directoryFiles.splice(i,1)[0]);
}
}
return translationsFiles;
}
function removeComments(content)
{
// Remove comments
let currentCharacter = 'A'.charCodeAt();
for(let index=0;index<26; ++index)
{
content = content.replace("//"+String.fromCharCode(currentCharacter++),"");
}
return content;
}
function checkEntries(files)
{
for(let i=1;i<files.length;++i)
{
for(let currentEntry in files[0])
{
if(!files[i][currentEntry])
{
files[i][currentEntry] = '';
}
}
}
}
function beautifyAndWriteFile(JSONContent, beforeEqualText, filepath)
{
let content = JSON.stringify(JSONContent);
content = beforeEqualText + '\n' + content;
content = content.replace('{','{ ');
content = content.replace(/","/gi,'",\n "');
content = content.replace('}','\n}');
let currentCharacter = 'a'.charCodeAt(),
currentUpperCaseCharacter = 'A'.charCodeAt();
for(let index=0; index<26; ++index)
{
content = content.replace(' "'+String.fromCharCode(currentCharacter),'\n //'+String.fromCharCode(currentUpperCaseCharacter++)+'\n "'+String.fromCharCode(currentCharacter++))
}
fs.writeFileSync(filepath, content);
}
function addMissingEntries()
{
let directoryFiles = browseLocalesDirectory();
let translationsFiles = getLocalesFiles(directoryFiles);
let translationsFilesJSON = [],
beforeEqualTexts = [];
for(let index=0; index<translationsFiles.length; ++index)
{
let equalPosition = translationsFiles[index].indexOf('=');
beforeEqualTexts.push(translationsFiles[index].substring(0, equalPosition+1));
translationsFilesJSON[index] = JSON.parse(removeComments(translationsFiles[index].substring(equalPosition+1)));
}
checkEntries(translationsFilesJSON);
// No need to write the 'en.ts' file because it is our default file
translationsFilesJSON.shift();
beforeEqualTexts.shift();
directoryFiles.shift();
for(let index=0; index<translationsFilesJSON.length; ++index)
{
beautifyAndWriteFile(translationsFilesJSON[index], beforeEqualTexts[index], 'src/locales/'+directoryFiles[index]);
}
}
module.exports = addMissingEntries;
\ No newline at end of file
......@@ -11,7 +11,8 @@ var gulp = require('gulp'),
source = require('vinyl-source-stream'),
tsify = require("tsify"),
notifier = require('node-notifier'),
nunjucks = require('gulp-nunjucks');
nunjucks = require('gulp-nunjucks'),
addMissingEntries = require('./addMissingEntries');
function handleError(err)
{
......@@ -152,3 +153,7 @@ gulp.task('production', function() {
gulp.start('gzip_styles', 'gzip_js');
});
gulp.task('addMissingEntries', function ()
{
addMissingEntries();
});
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
......@@ -2,7 +2,8 @@
<div class="modal-content page-modal-content">
<span class="icon btn-back gogo-icon-material-design-icons-1" onclick="$('#modal-contribution').closeModal()"></span>
<h1>{{ 'collaborative.moderation' | i18n }}</h1>
{{ 'collaborative.moderation.paragaphs' | i18n | safe}}
<p>{{ 'collaborative.moderation.first.paragraph' | i18n | safe}}</p>
<p>{{ 'collaborative.moderation.second.paragraph' | i18n | safe}}</p>
<div class="page-modal-footer">
<button type="button"
onclick="$('#modal-contribution').closeModal()"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment