From cc360d587b3cb88f846d50e601762b8df1239e6a Mon Sep 17 00:00:00 2001 From: karan nagpal Date: Sat, 7 Jul 2018 20:23:43 +0530 Subject: [PATCH 1/5] Add Web Translation support Custom export now have 3rd option to generate translation for Web in Json format. --- Code.gs | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/Code.gs b/Code.gs index 247a4f2..78fe847 100644 --- a/Code.gs +++ b/Code.gs @@ -15,7 +15,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI The number of languages you support. Please check the README.md for more information on column positions. */ -var NUMBER_OF_LANGUAGES = 1; +var NUMBER_OF_LANGUAGES = 2; /* The script expects two columns for iOS and Android identifiers, respectively, @@ -40,6 +40,7 @@ var IOS_INCLUDES_LOCALIZABLE_ENUM = true; var LANGUAGE_IOS = 'iOS'; var LANGUAGE_ANDROID = 'Android'; +var LANGUAGE_WEB = 'Web'; var DEFAULT_LANGUAGE = LANGUAGE_IOS; @@ -50,6 +51,7 @@ function onOpen() { ui.createMenu('Custom Export') .addItem('iOS', 'exportForIos') .addItem('Android', 'exportForAndroid') + .addItem('Web (Json)', 'exportForWeb') .addToUi(); } @@ -71,6 +73,15 @@ function exportForAndroid() { exportSheet(e); } +function exportForWeb() { + var e = { + parameter: { + language: LANGUAGE_WEB + } + }; + exportSheet(e); +} + /* Fetches the active sheet, gets all of the data and displays the result strings. @@ -159,6 +170,9 @@ function makeString(object, textIndex, options) { case LANGUAGE_IOS: return makeIosString(object, textIndex, options); break; + case LANGUAGE_WEB: + return makeJsonString(object, textIndex, options); + break; default: break; } @@ -269,6 +283,33 @@ function makeIosString(object, textIndex, options) { return exportString; } +/* + Creates the Localizable.json file. +*/ +function makeJsonString(object, textIndex, options) { + + var exportString = ""; var prevIdentifier = ""; + exportString += "{\n"; + + for(var i=0; i Date: Mon, 9 Jul 2018 13:10:04 +0530 Subject: [PATCH 2/5] Update REDME.md Add instructions to export strings for web --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f97616f..ddb69ce 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # localizable-sheet-script -A Google Sheets script that will take a sheet in a specific format and return iOS and Android localization files. +A Google Sheets script that will take a sheet in a specific format and return iOS, Android and Web (Json) localization files. ## What it does -For Android it creates an XML resources file with all of the strings. For iOS it creates a Localizable enum with String constants, and a .strings file. +For Android it creates an XML resources file with all of the strings. For iOS it creates a Localizable enum with String constants, and a .strings file. For Web it creates .json file all the strings. ## Installing @@ -14,7 +14,7 @@ For Android it creates an XML resources file with all of the strings. For iOS it ## Usage 1. Open your sheet. -2. Go to **Custom Export** and select your **iOS** or **Android**. +2. Go to **Custom Export** and select your **iOS**, **Android** or **Web (Json)**. ## Sheet format @@ -41,7 +41,7 @@ The position of the first (iOS) column that is relevant to the script is changed ## Exported files -The exported files are the standard format (`strings.xml` or `Localizable.strings`) for the specific platforms. iOS also includes a `Localizable` `enum` which contains all of the keys as `static let` properties for code-completion and less typos.  +The exported files are the standard format (`strings.xml`, `Localizable.strings` or `strings.json`) for the specific platforms. iOS also includes a `Localizable` `enum` which contains all of the keys as `static let` properties for code-completion and less typos.  ## License: MIT From 23ef6b5c5ef3c753928e145e0eea05ffedfd2f8c Mon Sep 17 00:00:00 2001 From: karan nagpal Date: Mon, 9 Jul 2018 13:18:10 +0530 Subject: [PATCH 3/5] Update REDME.md Update sheet header columns sample. --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ddb69ce..94a4b9d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A Google Sheets script that will take a sheet in a specific format and return iO ## What it does -For Android it creates an XML resources file with all of the strings. For iOS it creates a Localizable enum with String constants, and a .strings file. For Web it creates .json file all the strings. +For Android it creates an XML resources file with all of the strings. For iOS it creates a Localizable enum with String constants, and a .strings file. For Web it creates .json file with all of the strings. ## Installing @@ -20,10 +20,10 @@ For Android it creates an XML resources file with all of the strings. For iOS it The script expects the sheet to be formatted in a specific way. -| ... arbitrary number of columns before iOS keys | **Identifier iOS** | **Identifier Android** | English text | German text | ... | -|-------------------------------------------------|--------------------|------------------------|--------------|-------------|-----| -| place whatever you want in here | login_button_title | login_button_title | Login | Einloggen | | -| | ... | ... | ... | ... | | +| ... arbitrary number of columns before iOS keys | **Identifier iOS** | **Identifier Android** | **Identifier Android** | English text | German text | ... | +|-------------------------------------------------|--------------------|------------------------|------------------------|--------------|-------------|-----| +| place whatever you want in here | login_button_title | login_button_title | login_button_title | Login | Einloggen | | +| | ... | ... | ... | ... | ... | | **The texts in bold cannot be changed!** The script depends on them to know which identifier is which. The other texts don't matter. From 23b3c1a288be735748851a381fd442f4f4320c03 Mon Sep 17 00:00:00 2001 From: karan nagpal Date: Mon, 9 Jul 2018 13:31:24 +0530 Subject: [PATCH 4/5] Add Sample.csv file --- Sample.csv | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Sample.csv diff --git a/Sample.csv b/Sample.csv new file mode 100644 index 0000000..9b8cb09 --- /dev/null +++ b/Sample.csv @@ -0,0 +1,6 @@ +Identifier iOS,Identifier Android,Identifier Web,English text,Arabic text +ok,ok,ok,Ok,حسنا +cancel,cancel,cancel,Cancel,الغاء +resend,resend,resend,Resend,اعد الارسال +submit,submit,submit,Submit,تم +send,send,send,Send,ارسل \ No newline at end of file From e26932dd2dcb0e239813511cfa1ee4258b32c6f7 Mon Sep 17 00:00:00 2001 From: karan nagpal Date: Mon, 9 Jul 2018 14:25:21 +0530 Subject: [PATCH 5/5] Update REDME.md Fixed Identifier Web wrong text --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 94a4b9d..9b0a807 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ For Android it creates an XML resources file with all of the strings. For iOS it The script expects the sheet to be formatted in a specific way. -| ... arbitrary number of columns before iOS keys | **Identifier iOS** | **Identifier Android** | **Identifier Android** | English text | German text | ... | +| ... arbitrary number of columns before iOS keys | **Identifier iOS** | **Identifier Android** | **Identifier Web** | English text | German text | ... | |-------------------------------------------------|--------------------|------------------------|------------------------|--------------|-------------|-----| | place whatever you want in here | login_button_title | login_button_title | login_button_title | Login | Einloggen | | | | ... | ... | ... | ... | ... | |