daily pastebin goal
44%
SHARE
TWEET

Untitled

a guest Mar 24th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. * Convert Spreadsheet data into strings.xml (android) and Localized.string (ios)
  3. * requierment:
  4.    * 3 sheets should be create (wordings, android, ios)
  5.    * wording sheet should have 3 column (comment_flag, key, value)
  6. **/
  7.  
  8. function convertSpreadSheetToMobileWordingsFile() {
  9.   var spreadSheet = SpreadsheetApp.getActiveSpreadsheet();  
  10.   var sheet = spreadSheet.getSheets()[0];
  11.   var data = sheet.getDataRange().getValues();
  12.  
  13.   var generatedAndroidFile = "<resources>" + "\n";
  14.   var generatedIosFile = "";
  15.  
  16.   for (var i = 1; i < data.length; i++) {
  17.     var comment = data[i][0];
  18.     var key = data[i][1];
  19.     var value = data[i][2];
  20.     if (key == '') {
  21.       generatedAndroidFile += "\n";
  22.       generatedIosFile += "\n"
  23.       continue;
  24.     }
  25.    
  26.     generatedAndroidFile += printLineAndroid(comment, key, value);
  27.     generatedIosFile += printLineIos(comment, key, value);
  28.   }
  29.  
  30.   generatedAndroidFile += "\n</resources>";
  31.   wroteGeneratedFile(1, generatedAndroidFile);
  32.  
  33.   wroteGeneratedFile(2, generatedIosFile);
  34. }
  35.  
  36. function wroteGeneratedFile(sheetNumber, generatedFile) {
  37.   var spreadSheet = SpreadsheetApp.getActiveSpreadsheet();  
  38.   var sheetToWrite = spreadSheet.getSheets()[sheetNumber];
  39.   var range = sheetToWrite.getRange('A1');
  40.   range.clear();
  41.   range.setValue(generatedFile);
  42.   // set style
  43.   range.setWrap(true);
  44.   range.setBackground("#2e2e2f");
  45.   range.setFontColor("#ffffff");
  46. }
  47.  
  48. // ----- ANDROID -----
  49.  
  50. function printLineAndroid(comment, key, value) {
  51.   if (comment == '//') {
  52.     var newLine = "<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->\n";
  53.     newLine += "<!-- " + key + " -->\n\n";
  54.     return newLine;
  55.   }
  56.   var newLine = "\t<string name=\"" + key + "\">" + value + "</string>\n";
  57.   return newLine;
  58. }
  59.  
  60. // ----- IOS -----
  61.  
  62. function printLineIos(comment, key, value) {
  63.   if (comment == '//') {
  64.     var newLine = "// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  65.     newLine += "// " + key + "\n\n";
  66.     return newLine;
  67.   }
  68.   var newLine = "\"" + key + "\" = \"" + value + "\";\n";
  69.   newLine = newLine.replace('%1$s', '%1$@');
  70.   newLine = newLine.replace('%2$s', '%2$@');
  71.   return newLine;
  72. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top