Treansifex and Build/Dist Scripts :shipit:

Finally a sensible and easy solution
This commit is contained in:
Thierry François 2018-02-28 21:12:05 +02:00
parent d4726cb5fe
commit 2b865a8e3b
35 changed files with 147 additions and 388 deletions

2
.gitignore vendored
View File

@ -3,7 +3,7 @@
.AppleDouble
.LSOverride
transifexAuth.json
.transifexrc
**/css/bourbon
**/.sass-cache
node_modules/

17
.tx/config Normal file
View File

@ -0,0 +1,17 @@
[main]
host = https://www.transifex.com
[gridfieldbulkeditingtools.yml]
file_filter = lang/<lang>.yml
minimum_perc = 0
source_file = lang/en.yml
source_lang = en
type = YML
[gridfieldbulkeditingtools.js]
file_filter = client/src/lang/<lang>.json
minimum_perc = 0
source_file = client/src/lang/en.json
source_lang = en
type = JSON

View File

@ -48,6 +48,10 @@ $config->addComponent(new \Colymba\BulkManager\BulkManager());
See [BULK_MANAGER.md](docs/en//BULK_MANAGER.md) for detailed configuration.
## Tooling
* `npm run watch` for development
* `npm run dist` before pushing to the repo
## Translations
Translations of the natural language strings are managed through a third party translation interface, transifex.com.

View File

@ -1,9 +1,7 @@
// DO NOT MODIFY. Generated by build task.
// Contribute here: https://www.transifex.com/projects/p/gridfieldbulkeditingtools/
if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
if(typeof(console) != 'undefined') console.error('Class ss.i18n not defined');
} else {
ss.i18n.addDictionary('cs', {
ss.i18n.addDictionary(cs, {
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "Uploading %s file(s). %s done. %s error(s).",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "Musíte vybrat alespoň jednu položku.",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "Data budou nenávratně ztracena. Opravdu chcete pokračovat?"

View File

@ -1,9 +1,7 @@
// DO NOT MODIFY. Generated by build task.
// Contribute here: https://www.transifex.com/projects/p/gridfieldbulkeditingtools/
if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
if(typeof(console) != 'undefined') console.error('Class ss.i18n not defined');
} else {
ss.i18n.addDictionary('de', {
ss.i18n.addDictionary(de, {
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "Übertrage %s Datei(en). %s erfolgreich übertragen. %s Fehler.",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "Sie müssen mindestens ein Element auswählen.",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "Wollen Sie dieses Element wirklich unwiderruflich löschen?"

View File

@ -1,11 +1,9 @@
// DO NOT MODIFY. Generated by build task.
// Contribute here: https://www.transifex.com/projects/p/gridfieldbulkeditingtools/
if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
if(typeof(console) != 'undefined') console.error('Class ss.i18n not defined');
} else {
ss.i18n.addDictionary('en', {
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "Uploading %s file(s). %s done. %s error(s).",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "You must select at least one record.",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "The data will be lost permanently. Do you want to continue?"
ss.i18n.addDictionary(en, {
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "Uploading %s file(s). %s done. %s error(s).",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "You must select at least one record.",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "The data will be lost permanently. Do you want to continue?"
});
}

View File

@ -1,9 +1,7 @@
// DO NOT MODIFY. Generated by build task.
// Contribute here: https://www.transifex.com/projects/p/gridfieldbulkeditingtools/
if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
if(typeof(console) != 'undefined') console.error('Class ss.i18n not defined');
} else {
ss.i18n.addDictionary('fi', {
ss.i18n.addDictionary(fi, {
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "Lataa %s tiedosto(ja). %s Valmis. %s virhe(itä).",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "Sinun täytyy valita vähintään yksi tallenne. ",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "Tiedostosi häviävät pysyvästi. Haluatko jatkaa?"

View File

@ -1,9 +1,7 @@
// DO NOT MODIFY. Generated by build task.
// Contribute here: https://www.transifex.com/projects/p/gridfieldbulkeditingtools/
if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
if(typeof(console) != 'undefined') console.error('Class ss.i18n not defined');
} else {
ss.i18n.addDictionary('fr', {
ss.i18n.addDictionary(fr, {
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "%s fichier(s) en transfert. %s terminer. %s erreur(s).",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "Vous devez sélectionner au moins une entrée.",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "Les données serons perdu définitivement. Voulez vous continuer?"

View File

@ -1,9 +1,7 @@
// DO NOT MODIFY. Generated by build task.
// Contribute here: https://www.transifex.com/projects/p/gridfieldbulkeditingtools/
if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
if(typeof(console) != 'undefined') console.error('Class ss.i18n not defined');
} else {
ss.i18n.addDictionary('it', {
ss.i18n.addDictionary(it, {
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "Caricamento del/dei file(s) %s. %s completato. %s errore(i).",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "Devi selezionare almeno una voce.",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "I dati saranno persi per sempre. Vuoi continuare?"

View File

@ -1,9 +1,7 @@
// DO NOT MODIFY. Generated by build task.
// Contribute here: https://www.transifex.com/projects/p/gridfieldbulkeditingtools/
if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
if(typeof(console) != 'undefined') console.error('Class ss.i18n not defined');
} else {
ss.i18n.addDictionary('nl', {
ss.i18n.addDictionary(nl, {
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "Uploading %s file(s). %s done. %s error(s).",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "U moet minstens een item te selecteren.",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "De gegevens zullen permanent verloren. Weet je zeker dat je de pagina wilt verlaten?"

View File

@ -1,9 +1,7 @@
// DO NOT MODIFY. Generated by build task.
// Contribute here: https://www.transifex.com/projects/p/gridfieldbulkeditingtools/
if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
if(typeof(console) != 'undefined') console.error('Class ss.i18n not defined');
} else {
ss.i18n.addDictionary('pl', {
ss.i18n.addDictionary(pl, {
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "Wgrywanie %s plików. Ukończono %s. %s błędów.",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "Musisz wybrać przynajmniej jedną pozycję.",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "Dane zostaną bezpowrotnie usunięte. Czy chcesz kontynuować?"

9
client/lang/ru.js Normal file
View File

@ -0,0 +1,9 @@
if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
if(typeof(console) != 'undefined') console.error('Class ss.i18n not defined');
} else {
ss.i18n.addDictionary(ru, {
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "Загружается %s файл(ов). %s завершено. %s ошибка(и).",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "Вы должны выбрать как минимум одну запись.",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "Ваши данные будут безвозвратно удалены. Вы хотите продолжить?"
});
}

View File

@ -1,9 +1,7 @@
// DO NOT MODIFY. Generated by build task.
// Contribute here: https://www.transifex.com/projects/p/gridfieldbulkeditingtools/
if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
if(typeof(console) != 'undefined') console.error('Class ss.i18n not defined');
} else {
ss.i18n.addDictionary('sk', {
ss.i18n.addDictionary(sk, {
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "Nahrávam %s súbor(y/ov). %s hotovo. %s chyb(a/y).",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "Musíte vybrať aspoň jednu položku.",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "Dáta budú nenávratne stratené. Chcete pokračovať?"

5
client/src/lang/cs.json Normal file
View File

@ -0,0 +1,5 @@
{
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "Uploading %s file(s). %s done. %s error(s).",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "Musíte vybrat alespoň jednu položku.",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "Data budou nenávratně ztracena. Opravdu chcete pokračovat?"
}

5
client/src/lang/de.json Normal file
View File

@ -0,0 +1,5 @@
{
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "Übertrage %s Datei(en). %s erfolgreich übertragen. %s Fehler.",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "Sie müssen mindestens ein Element auswählen.",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "Wollen Sie dieses Element wirklich unwiderruflich löschen?"
}

5
client/src/lang/fi.json Normal file
View File

@ -0,0 +1,5 @@
{
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "Lataa %s tiedosto(ja). %s Valmis. %s virhe(itä).",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "Sinun täytyy valita vähintään yksi tallenne. ",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "Tiedostosi häviävät pysyvästi. Haluatko jatkaa?"
}

5
client/src/lang/fr.json Normal file
View File

@ -0,0 +1,5 @@
{
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "%s fichier(s) en transfert. %s terminer. %s erreur(s).",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "Vous devez sélectionner au moins une entrée.",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "Les données serons perdu définitivement. Voulez vous continuer?"
}

5
client/src/lang/it.json Normal file
View File

@ -0,0 +1,5 @@
{
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "Caricamento del/dei file(s) %s. %s completato. %s errore(i).",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "Devi selezionare almeno una voce.",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "I dati saranno persi per sempre. Vuoi continuare?"
}

5
client/src/lang/nl.json Normal file
View File

@ -0,0 +1,5 @@
{
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "Uploading %s file(s). %s done. %s error(s).",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "U moet minstens een item te selecteren.",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "De gegevens zullen permanent verloren. Weet je zeker dat je de pagina wilt verlaten?"
}

5
client/src/lang/pl.json Normal file
View File

@ -0,0 +1,5 @@
{
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "Wgrywanie %s plików. Ukończono %s. %s błędów.",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "Musisz wybrać przynajmniej jedną pozycję.",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "Dane zostaną bezpowrotnie usunięte. Czy chcesz kontynuować?"
}

5
client/src/lang/ru.json Normal file
View File

@ -0,0 +1,5 @@
{
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "Загружается %s файл(ов). %s завершено. %s ошибка(и).",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "Вы должны выбрать как минимум одну запись.",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "Ваши данные будут безвозвратно удалены. Вы хотите продолжить?"
}

5
client/src/lang/sk.json Normal file
View File

@ -0,0 +1,5 @@
{
"GRIDFIELD_BULK_UPLOAD.PROGRESS_INFO": "Nahrávam %s súbor(y/ov). %s hotovo. %s chyb(a/y).",
"GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT": "Musíte vybrať aspoň jednu položku.",
"GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION": "Dáta budú nenávratne stratené. Chcete pokračovať?"
}

View File

@ -1,10 +1,4 @@
# DO NOT MODIFY. Generated by build task.
# Contribute here: https://www.transifex.com/projects/p/gridfieldbulkeditingtools/
cs:
GRIDFIELD_BULK_UPLOAD:
FINISH_BTN_LABEL: Dokončit
CANCEL_BTN_LABEL: Storno
EDIT_ALL_BTN_LABEL: Upravit vše
GRIDFIELD_BULK_MANAGER:
EDIT_SELECT_LABEL: Upravit
UNLINK_SELECT_LABEL: Odstranit vazbu

View File

@ -1,11 +1,4 @@
# DO NOT MODIFY. Generated by build task.
# Contribute here: https://www.transifex.com/projects/p/gridfieldbulkeditingtools/
de:
GRIDFIELD_BULK_UPLOAD:
FINISH_BTN_LABEL: Fertigstellen
CANCEL_BTN_LABEL: Abbrechen
CLEAR_ERROR_BTN_LABEL: Fehler löschen
EDIT_ALL_BTN_LABEL: Alle bearbeiten
GRIDFIELD_BULK_MANAGER:
COMPONENT_TITLE: Einen oder mehrere Einträge gleichzeitig bearbeiten
EDIT_SELECT_LABEL: Bearbeiten

View File

@ -1,9 +1,5 @@
en:
GRIDFIELD_BULK_UPLOAD:
FINISH_BTN_LABEL: Finish
CANCEL_BTN_LABEL: Cancel
CLEAR_ERROR_BTN_LABEL: Clear errors
EDIT_ALL_BTN_LABEL: Edit all
GRIDFIELD_BULK_MANAGER:
COMPONENT_TITLE: Modify one or more entry at a time.
EDIT_SELECT_LABEL: Edit

View File

@ -1,11 +1,4 @@
# DO NOT MODIFY. Generated by build task.
# Contribute here: https://www.transifex.com/projects/p/gridfieldbulkeditingtools/
fi:
GRIDFIELD_BULK_UPLOAD:
FINISH_BTN_LABEL: Valmis
CANCEL_BTN_LABEL: Peruuta
CLEAR_ERROR_BTN_LABEL: Selvitä virheet
EDIT_ALL_BTN_LABEL: Muokkaa kaikki
GRIDFIELD_BULK_MANAGER:
COMPONENT_TITLE: Muokkaa yhtä tai useampaa merkintää kerrallaan.
EDIT_SELECT_LABEL: Muokkaa

View File

@ -1,11 +1,4 @@
# DO NOT MODIFY. Generated by build task.
# Contribute here: https://www.transifex.com/projects/p/gridfieldbulkeditingtools/
fr:
GRIDFIELD_BULK_UPLOAD:
FINISH_BTN_LABEL: Terminer
CANCEL_BTN_LABEL: Annuler
CLEAR_ERROR_BTN_LABEL: Effacer les erreurs
EDIT_ALL_BTN_LABEL: Tout éditer
GRIDFIELD_BULK_MANAGER:
COMPONENT_TITLE: Modifier une ou plusieurs entrée à la fois.
EDIT_SELECT_LABEL: Editer

View File

@ -1,11 +1,4 @@
# DO NOT MODIFY. Generated by build task.
# Contribute here: https://www.transifex.com/projects/p/gridfieldbulkeditingtools/
it:
GRIDFIELD_BULK_UPLOAD:
FINISH_BTN_LABEL: Termina
CANCEL_BTN_LABEL: Annulla
CLEAR_ERROR_BTN_LABEL: Cancella errori
EDIT_ALL_BTN_LABEL: Modifica tutti
GRIDFIELD_BULK_MANAGER:
COMPONENT_TITLE: Modifica una o più voci alla volta.
EDIT_SELECT_LABEL: Modifica

View File

@ -1,11 +1,4 @@
# DO NOT MODIFY. Generated by build task.
# Contribute here: https://www.transifex.com/projects/p/gridfieldbulkeditingtools/
nl:
GRIDFIELD_BULK_UPLOAD:
FINISH_BTN_LABEL: Afronden
CANCEL_BTN_LABEL: Annuleren
CLEAR_ERROR_BTN_LABEL: Verwijder fouten
EDIT_ALL_BTN_LABEL: Alles bewerken
GRIDFIELD_BULK_MANAGER:
COMPONENT_TITLE: Bewerk één of meerdere items tegelijkertijd
EDIT_SELECT_LABEL: Bewerken

View File

@ -1,11 +1,4 @@
# DO NOT MODIFY. Generated by build task.
# Contribute here: https://www.transifex.com/projects/p/gridfieldbulkeditingtools/
pl:
GRIDFIELD_BULK_UPLOAD:
FINISH_BTN_LABEL: Zakończ
CANCEL_BTN_LABEL: Anuluj
CLEAR_ERROR_BTN_LABEL: Usuń błędy
EDIT_ALL_BTN_LABEL: Edytuj wszystkie
GRIDFIELD_BULK_MANAGER:
COMPONENT_TITLE: Modyfikuj jednocześnie jedną lub więcej pozycji.
EDIT_SELECT_LABEL: Edytuj

14
lang/ru.yml Normal file
View File

@ -0,0 +1,14 @@
ru:
GRIDFIELD_BULK_MANAGER:
COMPONENT_TITLE: Редактировать одну или несколько записей одновременно
EDIT_SELECT_LABEL: Редактировать
UNLINK_SELECT_LABEL: Отвязать
DELETE_SELECT_LABEL: Удалить
ACTION_BTN_LABEL: Поехали
SELECT_ALL_LABEL: Выбрать все
GRIDFIELD_BULKMANAGER_EDIT_HANDLER:
HEADER_TEXT: Редактировать {count} {class}
TOGGLE_ALL_LINK: Показать/Скрыть все
SAVE_BTN_LABEL: Сохранить все
CANCEL_BTN_LABEL: Отменить
SAVE_RESULT_TEXT: '{count} {class} успешно сохранены'

View File

@ -1,11 +1,4 @@
# DO NOT MODIFY. Generated by build task.
# Contribute here: https://www.transifex.com/projects/p/gridfieldbulkeditingtools/
sk:
GRIDFIELD_BULK_UPLOAD:
FINISH_BTN_LABEL: Dokončiť
CANCEL_BTN_LABEL: Zrušiť
CLEAR_ERROR_BTN_LABEL: Vymazať chyby
EDIT_ALL_BTN_LABEL: Upraviť všetky
GRIDFIELD_BULK_MANAGER:
COMPONENT_TITLE: Uprav jednu alebo viac položiek súčasne.
EDIT_SELECT_LABEL: Upraviť

View File

@ -7,7 +7,9 @@
},
"scripts": {
"build": "NODE_ENV=production webpack -p --bail --progress",
"watch": "NODE_ENV=development webpack --watch --progress"
"watch": "NODE_ENV=development webpack --watch --progress",
"tx": "tx push --source && tx pull --all && node transifex.js",
"dist": "npm run tx && npm run build"
},
"repository": {
"type": "git",

View File

@ -1,289 +0,0 @@
<?php
/**
* Phing build task used to generate SilverStripe translation files
* from Transifex data. This tasks assumes that:
* - Javascript translations are from the Transifex resource called 'js'
* - YML translations are from the Transifex resource called 'yml'
* - Transifex AUTH credentials to be saved in $txAuthFile with content {"username": "user", "password": "pwd"}.
*
* This is inspired by SilverStripe build tools. Thanks
*
* @see https://github.com/silverstripe/silverstripe-buildtools/blob/master/src/GenerateJavascriptI18nTask.php
*/
// Ignore this file if phing is not installed
if (!class_exists('Task')) {
return;
}
include_once 'phing/Task.php';
class BuildTransifexTranslations extends Task
{
private $txapi = 'https://www.transifex.com/api/2';
private $txproject = '';
private $txAuthFile = 'transifexAuth.json';
private $txAuth = null;
private $root = '';
private $jsDir = '/lang/js';
private $ymlDir = '/lang';
public function settxapi($txapi)
{
$this->txapi = $txapi;
}
public function settxproject($txproject)
{
$this->txproject = $txproject;
}
/**
* Task init.
*/
public function init()
{
$root = realpath(__DIR__.DIRECTORY_SEPARATOR.'..');
$authFile = $root.DIRECTORY_SEPARATOR.$this->txAuthFile;
if (file_exists($authFile)) {
$txAuthData = file_get_contents($authFile);
$txAuthData = json_decode($txAuthData);
if ($txAuthData->username && $txAuthData->password) {
$this->txAuth = $txAuthData;
} else {
throw new BuildException("Transifex credentials malformat. Check your $authFile for 'username' and 'password' keys.");
}
} else {
throw new BuildException("Transifex credentials not found. $authFile missing.");
}
$this->root = $root;
$this->jsDir = $root.$this->jsDir;
$this->ymlDir = $root.$this->ymlDir;
}
/**
* Let's get to buisness...
*/
public function main()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $this->txAuth->username.':'.$this->txAuth->password);
// get resources
$url = $this->txapi.'/project/'.$this->txproject.'/resources/';
curl_setopt($ch, CURLOPT_URL, $url);
$resources = curl_exec($ch);
if (!$resources) {
throw new BuildException('Cannot fetch resources');
} else {
$resources = json_decode($resources);
}
// get langs
$url = $this->txapi.'/project/'.$this->txproject.'/languages/';
curl_setopt($ch, CURLOPT_URL, $url);
$languages = curl_exec($ch);
if (!$languages) {
throw new BuildException('Cannot fetch languages');
} else {
$languages = json_decode($languages);
}
// clear existing translation files and/or setup folders
$this->resetTranslations();
// add source_language_code to languages list
$sourceLangs = array();
foreach ($resources as $resource) {
$lang = new StdClass();
$locale = $resource->source_language_code;
$lang->language_code = $locale;
if (!array_key_exists($locale, $sourceLangs)) {
$sourceLangs[$locale] = $lang;
}
}
$sourceLangs = array_values($sourceLangs);
$languages = array_merge($languages, $sourceLangs);
// get each resource translations
foreach ($resources as $resource) {
foreach ($languages as $language) {
$url = $this->txapi.'/project/'.$this->txproject.'/resource/'.$resource->slug.'/translation/'.$language->language_code;
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
if ($data) {
$this->saveTranslation($resource->slug, $language->language_code, $data);
}
}
}
curl_close($ch);
}
/**
* Clear any existing translation files
* and create directory structure if needed.
*/
private function resetTranslations()
{
if (file_exists($this->jsDir)) {
echo "Clearing js translations...\n";
$iterator = new GlobIterator($this->jsDir.DIRECTORY_SEPARATOR.'*.js');
foreach ($iterator as $fileInfo) {
if ($fileInfo->isFile()) {
$del = unlink($fileInfo->getRealPath());
}
}
}
if (file_exists($this->ymlDir)) {
echo "Clearing yml translations...\n";
$iterator = new GlobIterator($this->ymlDir.DIRECTORY_SEPARATOR.'*.yml');
foreach ($iterator as $fileInfo) {
if ($fileInfo->isFile()) {
$del = unlink($fileInfo->getRealPath());
}
}
}
if (!file_exists($this->jsDir)) {
echo "Creating js folders...\n";
mkdir($this->jsDir);
}
if (!file_exists($this->ymlDir)) {
echo "Creating yml folders...\n";
mkdir($this->ymlDir);
}
}
/**
* Hook that detect the translation type via resource slug
* and call corect saving function with data.
*
* @param string $resource Transifex resrouce slug
* @param string $locale Transifex locale
* @param string $data Raw Transifex translation data
*/
private function saveTranslation($resource, $locale, $data)
{
if (!$resource || !$locale || !$data) {
return;
}
$data = json_decode($data);
$translation = rtrim($data->content);
switch ($resource) {
case 'js':
$this->saveJSTranslation($locale, $translation);
break;
case 'yml':
$this->saveYMLTranslation($locale, $translation);
break;
}
}
/**
* Save a JS translation file
* Uses JSTemplate to fit with SilverStripe requirements.
*
* @param string $locale Locale code
* @param string $json JSON translation key:value
*/
private function saveJSTranslation($locale, $json)
{
echo "Saving $locale.js\n";
file_put_contents(
$this->jsDir.DIRECTORY_SEPARATOR.$locale.'.js',
$this->getBanner('js').
str_replace(
array(
'%TRANSLATIONS%',
'%LOCALE%',
),
array(
$json,
$locale,
),
$this->getJSTemplate()
)
);
}
/**
* Save a YML translation file.
*
* @param string $locale Locale code
* @param string $yml YML translation
*/
public function saveYMLTranslation($locale, $yml)
{
echo "Saving $locale.yml\n";
if ($locale !== 'en') {
$content = $this->getBanner('yml').$yml;
} else {
$content = $yml;
}
file_put_contents(
$this->ymlDir.DIRECTORY_SEPARATOR.$locale.'.yml',
$content
);
}
/**
* Return the commented file banner.
*
* @param string $type File type e.g js
*
* @return string The commented file banner
*/
private function getBanner($type)
{
switch (strtolower($type)) {
case 'yml':
$comment = '#';
break;
default:
$comment = '//';
break;
}
$banner = <<<TMPL
$comment DO NOT MODIFY. Generated by build task.
$comment Contribute here: https://www.transifex.com/projects/p/gridfieldbulkeditingtools/
TMPL;
return $banner;
}
/**
* Return the SilverStripe JS lang file template.
*
* @return string The JS file template
*/
private function getJSTemplate()
{
$tmpl = <<<TMPL
if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
if(typeof(console) != 'undefined') console.error('Class ss.i18n not defined');
} else {
ss.i18n.addDictionary('%LOCALE%', %TRANSLATIONS%);
}
TMPL;
return $tmpl;
}
}

34
transifex.js Normal file
View File

@ -0,0 +1,34 @@
/**
* Parse all source JS language files (JSON pulled from Transifex) from client/src/lang
* to SilverStripe i18n js file in client/lang
* Quick and dirty node script!
*/
var fs = require('fs');
var path = require('path');
const PATHS = {
SRC: path.resolve('client/src/lang'),
DIST: path.resolve('client/lang'),
};
console.log('Writing SS i18n JS lang files...');
fs.readdir(PATHS.SRC, function(err, files)
{
files.forEach(function (file) {
var lang = file.split('.').shift();
fs.readFile(PATHS.SRC + '/' + file, "utf8", function(err, data) {
if (err) { console.log(err); }
var fileData = `if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
if(typeof(console) != 'undefined') console.error('Class ss.i18n not defined');
} else {
ss.i18n.addDictionary(${lang}, ${data});
}`;
fs.writeFile(PATHS.DIST + '/' + lang + '.js', fileData, "utf8", function(err) {
if (err) { console.log(err); }
console.log("Saved " + lang + '.js');
});
});
});
});