Skip to content

Commit

Permalink
Changes in the way the translation files are generated
Browse files Browse the repository at this point in the history
To generate a better experience and avoid mismatches between the state of the different languages ​​I generated a script that compares the files.
When run 'npm run translations' the file './i18n/generic.json' is self-generated with all strings extracted from the application. After that the own script (i18n-diff.js) is executed, which returns the missing or oversubscribed translations in each language located in the i18n/translations folder.
Throughout the previous commits I was removing and correcting mistakes of typing and lost translations according to what different people were reporting.
  • Loading branch information
gmarcos87 committed Oct 19, 2017
1 parent ee532b1 commit 5d491a2
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .i18nrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"plugins": [
"preact-i18nline"
],
"outputFile": "i18n/translations/en.json"
"outputFile": "i18n/generic.json"
}
31 changes: 31 additions & 0 deletions i18n-diff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

const genericFile = require('./i18n/generic.json').en;
const translations = require('./i18n');
const colors = require('colors');

const missing = (master, slave) => {
const slaveKeys = Object.keys(slave);
return Object.keys(master).filter(key => slaveKeys.indexOf(key)=== -1);
};

const surplus = (master, slave) => {
const masterKeys = Object.keys(master);
return Object.keys(slave).filter(key => masterKeys.indexOf(key) === -1);
};

const init = () => {
console.log(colors.bold.underline('Translations differences'));

const translationsKeys = Object.keys(translations);

translationsKeys.forEach((lang) => {
const translationsMissing = missing(genericFile,translations[lang]);
const translationsSurplus = surplus(genericFile,translations[lang]);

console.log(colors.bold(' ./i18n/translations/' + lang + '.json'))
translationsMissing.map(x => console.log(colors.green(' +++ '+ x)))
translationsSurplus.map(x => console.log(colors.red(' --- '+ x)))
});
};

init();
40 changes: 40 additions & 0 deletions i18n/generic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"en": {
"align_11050992": "Align",
"interfaces_44f8a99c": "Interfaces",
"stations_18122820": "Stations",
"config_4877f466": "Config",
"current_status_830c5a75": "Current status",
"connected_host_91e11459": "Connected Host",
"base_host_a17d45a4": "Base Host",
"select_new_base_station_3652ae73": "Select new base station",
"change_dcaa253a": "Change",
"locate_5f6685db": "Locate",
"station_75bce853": "Station",
"move_to_new_position_eb97c4c3": "MOVE TO NEW POSITION",
"packet_loss_1afe48a8": "Packet loss",
"metrics_c80fba05": "Metrics",
"metrics_status_gateway_2a77a113": "metrics_status_gateway",
"metrics_status_path_905a8d22": "metrics_status_path",
"metrics_status_stations_464641e8": "metrics_status_stations",
"load_last_known_internet_path_677f6229": "load_last_known_internet_path",
"only_gateway_727b1656": "Only gateway",
"full_path_metrics_2859608f": "Full path metrics",
"internet_connection_fda60ffa": "Internet connection",
"from_fdd4956d": "From",
"to_internet_494eb85c": "To Internet",
"notes_c42e0fd5": "Notes",
"notes_of_a44a4158": "Notes of",
"save_notes_616850ea": "Save notes",
"status_e7fdbe06": "Status",
"system_55b0ca91": "System",
"uptime_c1d2415d": "Uptime",
"most_active_2d5a3cae": "Most Active",
"interface_177dac54": "Interface",
"traffic_bfe536d2": "Traffic",
"loading_node_status_547ed318": "Loading node status...",
"ip_addresses_440ac240": "IP Addresses",
"back_to_base_443797cb": "Back to base",
"trying_to_connect_ff82bf9f": "Trying to connect"
}
}
6 changes: 6 additions & 0 deletions i18n/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require('fs').readdirSync(__dirname + '/translations/').forEach((file) => {
if (file.match(/\.json$/) !== null) {
let name = file.replace('.json', '');
exports[name] = require('./translations/' + file);
}
});
22 changes: 8 additions & 14 deletions i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,27 @@
"back_to_base_443797cb" :"Back to base",
"base_host_a17d45a4" :"Base Host",
"change_dcaa253a" :"Change",
"conected_host_f092f668" :"Conected Host",
"connected_host_91e11459": "Connected Host",
"config_4877f466" :"Config",
"current_status_830c5a75" :"Current status",
"from_fdd4956d" :"From",
"full_path_metrics_2859608f" :"Full path metrics",
"get_metrics_e0f17084" :"Get metrics",
"home_351838cd" :"Home",
"i18n_t_notes_of_5e450f0a" :"%{i18n_t_notes_of}",
"intefaces_bec06316" :"Intefaces",
"interface_177dac54" :"Interface",
"internet_connection_fda60ffa" :"Internet connection",
"ip_addresses_440ac240" :"IP Addresses",
"load_last_known_internet_path" :"Load last known Internet path",
"load_last_known_internet_path_677f6229" :"Load last known Internet path",
"loading_node_status_547ed318" :"Loading node status...",
"locate_5f6685db" :"Locate",
"metrics_c80fba05" :"Metrics",
"metrics_status_gateway" :"Searching gateway",
"metrics_status_path" :"Calculating network path",
"metrics_status_stations" :"Measuring links",
"metrics_status_gateway_2a77a113" :"Searching gateway",
"metrics_status_path_905a8d22" :"Calculating network path",
"metrics_status_stations_464641e8" :"Measuring links",
"most_active_2d5a3cae" :"Most Active",
"move_to_new_position_eb97c4c3" :"MOVE TO NEW POSITION",
"node_c1b1dc58" :"Node",
"notes_c42e0fd5" :"Notes",
"notes_of_a44a4158" :"Notes of",
"only_gateway_727b1656" :"Only gateway",
"package_loss_a81b6c86" :"Package loss",
"pres_to_enable_changes_7cdfc920" :"PRES TO ENABLE CHANGES",
"packet_loss_1afe48a8": "Packet loss",
"save_notes_616850ea" :"Save notes",
"select_new_base_station_3652ae73" :"Select new base station",
"station_75bce853" :"Station",
Expand All @@ -40,5 +34,5 @@
"traffic_bfe536d2" :"Traffic",
"trying_to_connect_ff82bf9f" :"Trying to connect to %{meta_ws}",
"uptime_c1d2415d" :"Uptime",
"user_c95de254" :"User"
}
"interfaces_44f8a99c": "Interfaces"
}
22 changes: 9 additions & 13 deletions i18n/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,27 @@
"base_host_a17d45a4" : "Nodo local",
"back_to_base_443797cb": "Volver al nodo local",
"change_dcaa253a" : "Cambiar",
"conected_host_f092f668" : "Nodo seleccionado",
"connected_host_91e11459": "Nodo seleccionado",
"config_4877f466" : "Configuración",
"current_status_830c5a75" : "Estado acutal",
"from_fdd4956d" : "Desde",
"full_path_metrics_2859608f" : "Medir todo el recorrido",
"get_metrics_e0f17084" : "Obtener mediciones",
"home_351838cd" : "Inicio",
"intefaces_bec06316" : "Intefaces",
"interface_177dac54" : "Interfaz",
"internet_connection_fda60ffa" : "Conexión a Internet",
"ip_addresses_440ac240" : "Direcciones IP",
"load_last_known_internet_path" : "Cargando utlimo recorrido conocido",
"load_last_known_internet_path_677f6229" : "Cargando utlimo recorrido conocido",
"loading_node_status_547ed318" : "Cargando el estado del nodo...",
"locate_5f6685db" : "Ubicación",
"metrics_c80fba05" : "Diagnostico",
"metrics_status_gateway" : "Buscando tu salida a Internet",
"metrics_status_path" : "Cargando el recorrido en la red",
"metrics_status_stations" : "Midiendo enlace",
"metrics_status_gateway_2a77a113" : "Buscando tu salida a Internet",
"metrics_status_path_905a8d22" : "Cargando el recorrido en la red",
"metrics_status_stations_464641e8" : "Midiendo enlace",
"most_active_2d5a3cae" : "Enlace más activo",
"move_to_new_position_eb97c4c3" : "MOVER A LA NUEVA POSICIÓN",
"node_c1b1dc58" : "Nodo",
"notes_c42e0fd5" : "Notas",
"notes_of_a44a4158" : "Notas de",
"only_gateway_727b1656" : "Medir sólo el gateway",
"package_loss_a81b6c86" : "Paquetes perdidos",
"pres_to_enable_changes_7cdfc920" : "PRESIONA PARA EDITAR",
"packet_loss_1afe48a8": "Paquetes perdidos",
"save_notes_616850ea" : "Guardar notas",
"select_new_base_station_3652ae73" : "Cambiar de nodo seleccionado",
"stations_18122820" : "Nodos ",
Expand All @@ -38,5 +33,6 @@
"traffic_bfe536d2" : "Trafico",
"trying_to_connect_ff82bf9f" : "Intentando conectar con %{meta_ws}",
"uptime_c1d2415d" : "Encendido",
"user_c95de254" : "Usuario"
}
"interfaces_44f8a99c": "Interfaces",
"station_75bce853" :"Nodo"
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"test": "npm run -s lint && npm run -s test:karma",
"test:karma": "karma start test/karma.conf.js --single-run",
"lint": "eslint ./",
"translations": "node ./node_modules/i18nline/bin/i18nline.js export"
"translations": "node ./node_modules/i18nline/bin/i18nline.js export",
"posttranslations": "node ./i18n-diff.js"
},
"keywords": [
"preact",
Expand All @@ -37,6 +38,7 @@
"babel-register": "^6.26.0",
"babel-runtime": "^6.26.0",
"chai": "^4.1.2",
"colors": "^1.1.2",
"copy-webpack-plugin": "^4.0.1",
"core-js": "^2.5.1",
"cross-env": "^5.0.5",
Expand Down

0 comments on commit 5d491a2

Please sign in to comment.