Skip to content

Commit

Permalink
Added loop for evaluation of multiple variables
Browse files Browse the repository at this point in the history
  • Loading branch information
phynet committed Sep 13, 2017
1 parent 4b1e24d commit eb9e62e
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 28 deletions.
71 changes: 53 additions & 18 deletions android-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,33 @@ function toAndroid(data, lang, dataPls,fileName){
docu += dataPls;
console.log('docu is: ' + docu);
}
createBodyHTML(data, lang, docu, endDoc, fileName);
}

function createBodyHTML(data, lang, docu, endDoc, fileName){
if (data){
for(var key in data) {
var kValue = (lang == '' ) ? data[key] : key ;
//add here evaluation for wildcards
var dataValue = parseWildcardsForAndroid(data[key]);
if (key == 'app_viendo_x_inmu_de_y'){
console.log('PARSE ' + dataValue);
}

docu += '<string name="' + kValue + '">' + dataValue +'</string>' +'\r\n';
}
docu += endDoc;
console.log(docu);
// Save in Disk
var moduleClass = require('./formatFiles');
moduleClass.saveInDisk(fileName, docu);
saveInDisk(fileName, docu);
}
}

function saveInDisk(fileName, docu){
var moduleClass = require('./formatFiles');
moduleClass.saveInDisk(fileName, docu);
}

function parseWildcardsForAndroid(data){
//first tipology with incremental variables
//**1s** **2d** **3f**
Expand All @@ -81,26 +93,49 @@ function parseWithRegex(data){
}

function regexCardinalVariables(data){
var regex = /\**\d+\w/g;
var numberWithAsterix = data.match(regex);
//return **1s
if (numberWithAsterix){
//add symbolic escaping %% that is needed in android but not in iOS
var deleteAsterix = /\d+/g;
var number = String(numberWithAsterix).match(deleteAsterix);
//return 1 from **1s
var regexLetter = /\**\d\w/g;
var letterWithAsterix = data.match(regexLetter);
//return **1s for example
var deleteAsterixLetter = /([a-z])/g;
var letter = String(letterWithAsterix).match(deleteAsterixLetter);
//return s from **1s
data = data.replace("**"+number+letter+"**","%"+number+"$"+letter);
console.log("data replaced 1 " + data);
var regex = /\**\d+\w/g;
var numberWithAsterix = data.match(regex);
//return **1s
if (numberWithAsterix){

var number = [getNumber(data)];
var letter = [getLetter(data)];
var length = 0;

number = number.toString().split(",").map(Number);
letter = letter.toString().split(",").map(String);

length = number.length;

for (var indx = 0; indx <= length; indx++){
var ast = /\*\*/g;
var argRegEx = new RegExp(number[indx] + letter[indx], 'g');
var replc = "%"+number[indx]+"$"+letter[indx];

var rest = data.replace(argRegEx, replc);
data = rest.replace(ast, "");
console.log("final data replacing wildcards android" + data);
}
}
return data;
}

function getLetter(data){
var regexLetter = /\**\d\w/g;
var letterWithAsterix = data.match(regexLetter);
//return **1s for example
var deleteAsterixLetter = /([a-z])/g;
return String(letterWithAsterix).match(deleteAsterixLetter);
}

function getNumber(data){
//add symbolic escaping %% that is needed in android but not in iOS
var regex = /\**\d+\w/g;
var numberWithAsterix = data.match(regex);
var deleteAsterix = /\d+/g;
return String(numberWithAsterix).match(deleteAsterix);
}

function regexEscapingSymbol(data){
var regexSymbolic = /\*\%/g;
var dataWithSymbolic = data.match(regexSymbolic);
Expand Down
56 changes: 46 additions & 10 deletions formatFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,71 @@ function pluralsFileCreator(nonPluralCSV, pluralsCSV, callback){
var htmliOS = "";

for (var lang in dictNonPls){
htmliOS += moduleClassiOS.headerHTMLiOS();
htmliOS += wrapperModuleiOSHeaderHTML;
for (var identifier in dictPls){
for(var value in dictPls[identifier]){
if (value == lang){
htmlAndroid += moduleClassAndroid.bodyNameForPlurals(identifier);
htmliOS += moduleClassiOS.bodyWithIDHTMLiOS(identifier);
htmlAndroid += wrapperModuleAndroidBodyName(identifier);
htmliOS += wrapperModuleiOSBodyName(identifier);
for (var val in dictPls[identifier][value]){
var valIdentifier = dictPls[identifier][value][val];
if(valIdentifier != ''){
htmliOS += moduleClassiOS.bodyHTMLiOS(val,valIdentifier);
htmlAndroid += moduleClassAndroid.bodyHTMLAndroid(val,valIdentifier);
htmliOS += wrapperModuleiOSBodyHTML(val,valIdentifier);
htmlAndroid += wrapperModuleAndroidBodyHTML(val,valIdentifier);
}
}
htmlAndroid += moduleClassAndroid.footerHTMLAndroid();
htmliOS += moduleClassiOS.footerHTMLiOS();
htmlAndroid += wrapperModuleAndroidFooterHMTL;
htmliOS += wrapperModuleiOSFooterHTML;
}
}
}
var data = dictNonPls[lang];
htmliOS += moduleClassiOS.footerCloseHTMLiOS();
moduleClassAndroid.toAndroid(data, lang, htmlAndroid,_fileName);
moduleClassiOS.toiOS(data,lang,_fileName);
moduleClassiOS.toiOSPlurals(htmliOS,lang,_fileName); //save plurals
goToModules(data, lang, htmlAndroid,htmliOS,_fileName)
htmlAndroid = "";
htmliOS = "";
}
callback(CALLBACK_MESSAGE.SUCCESS);
}

function wrapperModuleiOSHeaderHTML(){
return moduleClassiOS.headerHTMLiOS();
}

function wrapperModuleAndroidBodyName(identifier){
return moduleClassAndroid.bodyNameForPlurals(identifier);
}

function wrapperModuleiOSBodyName(identifier){
return moduleClassiOS.bodyWithIDHTMLiOS(identifier);
}

function wrapperModuleiOSBodyHTML(val, identifier){
return moduleClassiOS.bodyHTMLiOS(val,valIdentifier);
}

function wrapperModuleAndroidBodyHTML(val, identifier){
return moduleClassAndroid.bodyHTMLAndroid(val,valIdentifier);
}

function wrapperModuleiOSFooterHTML(){
return moduleClassiOS.footerHTMLiOS();
}

function wrapperModuleAndroidFooterHMTL(){
return moduleClassAndroid.footerHTMLAndroid();
}

function wrapperModuleiOSFooterCloseHTML(){
return moduleClassiOS.footerCloseHTMLiOS();
}

function goToModules(data, lang, htmlAndroid,htmliOS, fileName){
moduleClassAndroid.toAndroid(data, lang, htmlAndroid,fileName);
moduleClassiOS.toiOS(data,lang,fileName);
moduleClassiOS.toiOSPlurals(htmliOS,lang,fileName);
}

function nonPluralFileCreator(csv, callback){
var dictLangs = nonPluralsDictionaryData(csv);
//There are at least a key column and one or more language columns.
Expand Down

0 comments on commit eb9e62e

Please sign in to comment.