├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── docs └── png │ ├── androlate-droid.png │ └── androlate-logo.png ├── examples └── HelloWorld │ ├── .gitignore │ ├── .idea │ ├── .name │ ├── compiler.xml │ ├── copyright │ │ └── profiles_settings.xml │ ├── encodings.xml │ ├── gradle.xml │ ├── misc.xml │ ├── modules.xml │ ├── scopes │ │ └── scope_settings.xml │ └── vcs.xml │ ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── ayvazj │ │ │ └── gradle │ │ │ └── plugins │ │ │ └── androlate │ │ │ └── helloworld │ │ │ └── ApplicationTest.java │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── ayvazj │ │ │ └── gradle │ │ │ └── plugins │ │ │ └── androlate │ │ │ └── helloworld │ │ │ └── MainActivity.java │ │ └── res │ │ ├── drawable-hdpi │ │ └── ic_launcher.png │ │ ├── drawable-mdpi │ │ └── ic_launcher.png │ │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ │ ├── layout │ │ └── activity_main.xml │ │ ├── menu │ │ └── menu_main.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── hellolibrary │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── ayvazj │ │ │ └── gradle │ │ │ └── plugins │ │ │ └── androlate │ │ │ └── helloworld │ │ │ └── library │ │ │ └── ApplicationTest.java │ │ └── main │ │ ├── AndroidManifest.xml │ │ └── res │ │ ├── drawable-hdpi │ │ └── ic_launcher.png │ │ ├── drawable-mdpi │ │ └── ic_launcher.png │ │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ │ ├── values-es │ │ └── strings.xml │ │ └── values │ │ └── strings.xml │ └── settings.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties ├── settings.gradle └── src ├── main ├── groovy │ └── com │ │ └── github │ │ └── ayvazj │ │ └── gradle │ │ └── plugins │ │ └── androlate │ │ ├── Androlate.groovy │ │ ├── AndrolateBaseElement.groovy │ │ ├── AndrolateExportAppleTask.groovy │ │ ├── AndrolateExportExcelTask.groovy │ │ ├── AndrolatePlugin.groovy │ │ ├── AndrolatePluginExtension.groovy │ │ ├── AndrolateStringArrayElement.groovy │ │ ├── AndrolateStringElement.groovy │ │ ├── AndrolateTranslateTask.groovy │ │ └── AndrolateUtils.groovy └── resources │ └── META-INF │ └── gradle-plugins │ ├── androlate.properties │ └── com.github.ayvazj.plugins.androlate.properties └── test └── groovy └── com └── github └── ayvazj └── gradle └── plugins └── androlate └── AndrolatePluginTest.groovy /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | .idea 3 | build/ 4 | 5 | # Ignore Gradle GUI config 6 | gradle-app.setting 7 | 8 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 9 | !gradle-wrapper.jar 10 | *.ipr 11 | *.iml 12 | *.iws 13 | .gradle 14 | example/target 15 | build 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Androlate Gradle Plugin 2 | 3 | This plugin translates the string resources in your Android project using the 4 | [Google Translate] (https://translate.google.com/). It also provides a few extras to help with common translation tasks. 5 | 6 |

7 | Androlate Logo 8 |

9 | 10 | LEGAL INFORMATION 11 | --------------------- 12 | 13 | THIS PLUGIN MAY CONTAIN TRANSLATIONS POWERED BY GOOGLE. GOOGLE DISCLAIMS ALL 14 | WARRANTIES RELATED TO THE TRANSLATIONS, EXPRESS OR IMPLIED, INCLUDING ANY 15 | WARRANTIES OF ACCURACY, RELIABILITY, AND ANY IMPLIED WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | 18 | The Androlate plugin performs translations for your convenience 19 | using translation software powered by Google Translate. Reasonable efforts have 20 | been made to provide an accurate translation, however, no automated translation 21 | is perfect nor is it intended to replace human translators. Translations are provided 22 | as a service to users of the Androlate tool, and are provided "as is." No warranty of 23 | any kind, either expressed or implied, is made as to the accuracy, reliability, 24 | or correctness of any translations made from into any other 25 | language. Some content (such as images, videos, Flash, etc.) may not be accurately 26 | translated due to the limitations of the translation software. 27 | 28 | Any discrepancies or differences created in the translation are not binding and 29 | have no legal effect for compliance or enforcement purposes. 30 | 31 | IMPORTANT INFORMATION 32 | --------------------- 33 | * [Google Translate] (https://translate.google.com/) is a **PAID** service. 34 | I am in no way responsible for any fees incurred as a result of using this tool 35 | *including bugs*. **IT IS YOUR RESPONSIBILITY TO MONITOR USAGE AND BILLING**. 36 | 37 | * In order for translations to work you **MUST** have the Google Translate API enabled in the 38 | [Google Developer Console] (https://console.developers.google.com/). 39 | 40 | * YOU **MUST** HAVE BILLING ENABLED IN ORDER FOR THE TRANSLATE API TO WORK. 41 | This means you must add a credit card to your Google Developer Console account and enable 42 | for the google translate API. 43 | 44 | 45 | KNOWN ISSUES 46 | ------------ 47 | 48 | * [Google Translate] (https://translate.google.com/) may shuffle words around since it is designed for natural language translations. 49 | 50 | Example: Line1 nl Line2 nl Line3 => Línea 1 Línea 2 nl nl Line3 51 | 52 | * Some escape and formatting characters may not work (\\n, %1$s). You will need to review the generated strings and correct mistakes manually. 53 | 54 | * Embedded html markup may be stripped by the Google Translate API (i.e. Hello <b>World!</b>) 55 | * sections inside item elements won't be translated at this time. 56 | 57 | ## Examples 58 | 59 | An example projects can be found in [/examples](examples). 60 | 61 | ## Usage 62 | 63 | Modify your **modules** build.gradle file, not the project's root build.gradle file. 64 | 65 | Add the androlate plug buildscript.dependencies section 66 | 67 | buildscript { 68 | repositories { 69 | jcenter() 70 | } 71 | dependencies { 72 | classpath('com.github.ayvazj.gradle.plugins.androlate:androlate:0.3') 73 | } 74 | } 75 | 76 | Apply the plugin after the 'com.android.application' or 'com.android.library' plugins 77 | 78 | apply plugin: 'com.android.application' 79 | apply plugin: 'androlate' 80 | 81 | Add the following section to your build.gradle file 82 | 83 | androlate { 84 | appName = 'API Project' 85 | apiKey = '********************************' 86 | defaultLanguage = 'en' 87 | targetLanguages = ['es'] 88 | backup = true 89 | } 90 | 91 | Where: 92 | 93 | appName 94 | The name of the app you entered into the [Google Developer Console] (https://console.developers.google.com/) 95 | 96 | apiKey 97 | The API key obtained when you enable the Translate API key in the 98 | [Google Developer Console] (https://console.developers.google.com/). 99 | 100 | defaultLanguage 101 | The source language or the language that values/strings.xml is written in. This value will be passed to 102 | [Google Translate] (https://translate.google.com/) as the input language. 103 | 104 | targetLanguages 105 | A list of languages you are targeting. Keep in mind androlate will submit each string to 106 | [Google Translate] (https://translate.google.com/) so complete translations may take a while and result in fees. 107 | 108 | backup 109 | True if string files should be backed up before modification. 110 | 111 | 112 | Run the androlate target to translate the string resources 113 | 114 | > ./gradlew -q androlate 115 | 116 | Your strings files will be parsed and sent to [Google Translate] (https://translate.google.com/) for translation. The result will be stored in the values- directory with the same name as the source file. 117 | 118 | ## Additional information 119 | 120 | ####Unnecessary Translations *(and fees)* 121 | In order to avoid unnecessary translations androlate generates an md5 checksum for all of the strings in your default language. Only when the strings value does not match the md5sum is the string sent for translation. This ensures that on repeated runs only strings that have changed are sent for translation. 122 | 123 | Hello world! 124 | 125 | ## Bonus features 126 | 127 | Extras tasks were added to help with common translation tasks. 128 | 129 | ####Export strings to iOS / Mac strings. 130 | The resulting files will be located under the export/apple directory. 131 | 132 | > ./gradlew -q androlate-export-apple 133 | 134 | 135 | [doc]: http://ayvazj.github.io/gradle-androlate-plugin/doc/latest/ 136 | [javadoc]: http://ayvazj.github.io/gradle-androlate-plugin/doc/latest/javadoc/ 137 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | jcenter() 5 | } 6 | 7 | dependencies { 8 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.1' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | mavenCentral() 15 | } 16 | 17 | group = GROUP 18 | version = VERSION_NAME 19 | 20 | } 21 | 22 | apply plugin: 'groovy' 23 | apply plugin: 'maven' 24 | apply plugin: 'signing' 25 | apply plugin: 'com.jfrog.bintray' 26 | 27 | targetCompatibility = JavaVersion.VERSION_1_7 28 | sourceCompatibility = JavaVersion.VERSION_1_7 29 | 30 | dependencies { 31 | compile gradleApi() 32 | compile localGroovy() 33 | compile 'com.android.tools.build:gradle:1.1.0-rc3' 34 | compile 'com.google.api-client:google-api-client:1.18.0-rc' 35 | compile 'com.google.apis:google-api-services-translate:v2-rev41-1.20.0' 36 | compile 'commons-lang:commons-lang:2.6' 37 | } 38 | 39 | task wrapper(type: Wrapper) { 40 | gradleVersion = '2.0' 41 | } 42 | 43 | task javadocJar(type: Jar) { 44 | classifier = 'javadoc' 45 | from javadoc 46 | } 47 | 48 | task sourcesJar(type: Jar) { 49 | classifier = 'sources' 50 | from sourceSets.main.allSource 51 | } 52 | 53 | artifacts { 54 | archives javadocJar, sourcesJar 55 | } 56 | 57 | signing { 58 | sign configurations.archives 59 | } 60 | 61 | 62 | uploadArchives { 63 | repositories { 64 | mavenDeployer { 65 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 66 | 67 | mavenLocal() 68 | 69 | repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { 70 | authentication(userName: ossrhUsername, password: ossrhPassword) 71 | } 72 | 73 | snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { 74 | authentication(userName: ossrhUsername, password: ossrhPassword) 75 | } 76 | 77 | pom.project { 78 | name 'Androlate Plugin' 79 | // optionally artifactId can be defined here 80 | description POM_DESCRIPTION 81 | url POM_URL 82 | 83 | scm { 84 | connection POM_SCM_CONNECTION 85 | developerConnection POM_SCM_DEV_CONNECTION 86 | url POM_SCM_URL 87 | } 88 | 89 | licenses { 90 | license { 91 | name POM_LICENCE_NAME 92 | url POM_LICENCE_URL 93 | distribution POM_LICENCE_DIST 94 | } 95 | } 96 | 97 | developers { 98 | developer { 99 | id POM_DEVELOPER_ID 100 | name POM_DEVELOPER_NAME 101 | } 102 | } 103 | } 104 | } 105 | } 106 | } 107 | 108 | task writeNewPom << { 109 | pom { 110 | project { 111 | name 'Androlate Plugin' 112 | // optionally artifactId can be defined here 113 | description POM_DESCRIPTION 114 | url POM_URL 115 | 116 | scm { 117 | connection POM_SCM_CONNECTION 118 | developerConnection POM_SCM_DEV_CONNECTION 119 | url POM_SCM_URL 120 | } 121 | 122 | licenses { 123 | license { 124 | name POM_LICENCE_NAME 125 | url POM_LICENCE_URL 126 | distribution POM_LICENCE_DIST 127 | } 128 | } 129 | 130 | developers { 131 | developer { 132 | id POM_DEVELOPER_ID 133 | name POM_DEVELOPER_NAME 134 | } 135 | } 136 | } 137 | }.writeTo("$buildDir/poms/pom-default.xml") 138 | } 139 | 140 | bintray { 141 | user = bintrayUsername 142 | key = bintrayKey 143 | 144 | configurations = ['archives'] 145 | pkg { 146 | repo = "maven" 147 | name = "Androlate" 148 | //userOrg = 'myorg' //An optional organization name when the repo belongs to one of the user's orgs 149 | desc = POM_DESCRIPTION 150 | websiteUrl = POM_URL 151 | //issueTrackerUrl = 'https://github.com/bintray/gradle-bintray-plugin/issues' 152 | vcsUrl = POM_SCM_URL 153 | licenses = ["Apache-2.0"] 154 | labels = ['android', 'translate', 'i18n', 'internationalization', 'translations'] 155 | // publicDownloadNumbers = true 156 | // attributes= ['a': ['ay1', 'ay2'], 'b': ['bee'], c: 'cee'] //Optional package-level attributes 157 | } 158 | publish = true 159 | } -------------------------------------------------------------------------------- /docs/png/androlate-droid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayvazj/gradle-androlate-plugin/1b720545ef1330dec2ff1d30c7b7e6a04008b36c/docs/png/androlate-droid.png -------------------------------------------------------------------------------- /docs/png/androlate-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayvazj/gradle-androlate-plugin/1b720545ef1330dec2ff1d30c7b7e6a04008b36c/docs/png/androlate-logo.png -------------------------------------------------------------------------------- /examples/HelloWorld/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | -------------------------------------------------------------------------------- /examples/HelloWorld/.idea/.name: -------------------------------------------------------------------------------- 1 | Hello World -------------------------------------------------------------------------------- /examples/HelloWorld/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /examples/HelloWorld/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /examples/HelloWorld/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /examples/HelloWorld/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /examples/HelloWorld/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Android 15 | 16 | 17 | Android Lint 18 | 19 | 20 | Java language level migration aids 21 | 22 | 23 | 24 | 25 | Abstraction issues 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Android API 19 Platform 39 | 40 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /examples/HelloWorld/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /examples/HelloWorld/.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /examples/HelloWorld/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /examples/HelloWorld/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /examples/HelloWorld/app/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | mavenLocal() 5 | } 6 | dependencies { 7 | classpath('com.github.ayvazj.gradle.plugins.androlate:androlate:0.2') 8 | } 9 | } 10 | 11 | apply plugin: 'com.android.application' 12 | apply plugin: 'androlate' 13 | 14 | android { 15 | compileSdkVersion 21 16 | buildToolsVersion "21.1.2" 17 | 18 | defaultConfig { 19 | applicationId "com.github.ayvazj.gradle.plugins.androlate.helloworld" 20 | minSdkVersion 14 21 | targetSdkVersion 21 22 | versionCode 1 23 | versionName "1.0" 24 | } 25 | buildTypes { 26 | release { 27 | minifyEnabled false 28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 29 | } 30 | } 31 | } 32 | 33 | dependencies { 34 | compile fileTree(dir: 'libs', include: ['*.jar']) 35 | compile 'com.android.support:appcompat-v7:21.0.3' 36 | compile project(':hellolibrary') 37 | } 38 | 39 | 40 | androlate { 41 | appName = 'API Project' 42 | apiKey = GOOGLE_TRANSLATE_API_KEY 43 | defaultLanguage ='en' 44 | targetLanguages = ['es', 'ja', 'zh-CN'] 45 | backup = true 46 | } 47 | 48 | -------------------------------------------------------------------------------- /examples/HelloWorld/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/pwner/.android-sdk/android-sdk-macosx/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /examples/HelloWorld/app/src/androidTest/java/com/github/ayvazj/gradle/plugins/androlate/helloworld/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.github.ayvazj.gradle.plugins.androlate.helloworld; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /examples/HelloWorld/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /examples/HelloWorld/app/src/main/java/com/github/ayvazj/gradle/plugins/androlate/helloworld/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.github.ayvazj.gradle.plugins.androlate.helloworld; 2 | 3 | import android.support.v7.app.ActionBarActivity; 4 | import android.os.Bundle; 5 | import android.view.Menu; 6 | import android.view.MenuItem; 7 | 8 | 9 | public class MainActivity extends ActionBarActivity { 10 | 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | setContentView(R.layout.activity_main); 15 | } 16 | 17 | 18 | @Override 19 | public boolean onCreateOptionsMenu(Menu menu) { 20 | // Inflate the menu; this adds items to the action bar if it is present. 21 | getMenuInflater().inflate(R.menu.menu_main, menu); 22 | return true; 23 | } 24 | 25 | @Override 26 | public boolean onOptionsItemSelected(MenuItem item) { 27 | // Handle action bar item clicks here. The action bar will 28 | // automatically handle clicks on the Home/Up button, so long 29 | // as you specify a parent activity in AndroidManifest.xml. 30 | int id = item.getItemId(); 31 | 32 | //noinspection SimplifiableIfStatement 33 | if (id == R.id.action_settings) { 34 | return true; 35 | } 36 | 37 | return super.onOptionsItemSelected(item); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /examples/HelloWorld/app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayvazj/gradle-androlate-plugin/1b720545ef1330dec2ff1d30c7b7e6a04008b36c/examples/HelloWorld/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/HelloWorld/app/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayvazj/gradle-androlate-plugin/1b720545ef1330dec2ff1d30c7b7e6a04008b36c/examples/HelloWorld/app/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/HelloWorld/app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayvazj/gradle-androlate-plugin/1b720545ef1330dec2ff1d30c7b7e6a04008b36c/examples/HelloWorld/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/HelloWorld/app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayvazj/gradle-androlate-plugin/1b720545ef1330dec2ff1d30c7b7e6a04008b36c/examples/HelloWorld/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/HelloWorld/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 16 | 17 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /examples/HelloWorld/app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /examples/HelloWorld/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /examples/HelloWorld/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /examples/HelloWorld/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | hello World 3 | Hello world! 4 | Settings 5 | Hello World 6 | Line 1\nLine 2\nLine 3 7 | Hello %1$s, nice to meet you my name is %2$s 8 | 9 | String arrays are tricky 10 | So to keep it simple 11 | just translate the entire array together 12 | 13 | Welcome to Android! 14 | 15 | Not translated 16 | 17 | -------------------------------------------------------------------------------- /examples/HelloWorld/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/HelloWorld/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.0.0' 9 | // NOTE: Do not place your application dependencies here; they belong 10 | // in the individual module build.gradle files 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | jcenter() 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/HelloWorld/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | GOOGLE_TRANSLATE_API_KEY=YOURKEYHERE 21 | -------------------------------------------------------------------------------- /examples/HelloWorld/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayvazj/gradle-androlate-plugin/1b720545ef1330dec2ff1d30c7b7e6a04008b36c/examples/HelloWorld/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /examples/HelloWorld/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 10 15:27:10 PDT 2013 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /examples/HelloWorld/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /examples/HelloWorld/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /examples/HelloWorld/hellolibrary/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /examples/HelloWorld/hellolibrary/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | mavenLocal() 5 | } 6 | dependencies { 7 | classpath('com.github.ayvazj.gradle.plugins.androlate:androlate:0.2') 8 | } 9 | } 10 | 11 | apply plugin: 'com.android.library' 12 | apply plugin: 'androlate' 13 | 14 | android { 15 | compileSdkVersion 21 16 | buildToolsVersion "21.1.2" 17 | 18 | defaultConfig { 19 | minSdkVersion 14 20 | targetSdkVersion 21 21 | versionCode 1 22 | versionName "1.0" 23 | } 24 | buildTypes { 25 | release { 26 | minifyEnabled false 27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 28 | } 29 | } 30 | } 31 | 32 | dependencies { 33 | compile fileTree(dir: 'libs', include: ['*.jar']) 34 | compile 'com.android.support:appcompat-v7:21.0.3' 35 | } 36 | 37 | androlate { 38 | appName 'API Project' 39 | apiKey project.GOOGLE_TRANSLATE_API_KEY 40 | defaultLanguage 'en' 41 | targetLanguages = ['es'] 42 | } 43 | -------------------------------------------------------------------------------- /examples/HelloWorld/hellolibrary/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/pwner/.android-sdk/android-sdk-macosx/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /examples/HelloWorld/hellolibrary/src/androidTest/java/com/github/ayvazj/gradle/plugins/androlate/helloworld/library/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.github.ayvazj.gradle.plugins.androlate.helloworld.library; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /examples/HelloWorld/hellolibrary/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /examples/HelloWorld/hellolibrary/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayvazj/gradle-androlate-plugin/1b720545ef1330dec2ff1d30c7b7e6a04008b36c/examples/HelloWorld/hellolibrary/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/HelloWorld/hellolibrary/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayvazj/gradle-androlate-plugin/1b720545ef1330dec2ff1d30c7b7e6a04008b36c/examples/HelloWorld/hellolibrary/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/HelloWorld/hellolibrary/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayvazj/gradle-androlate-plugin/1b720545ef1330dec2ff1d30c7b7e6a04008b36c/examples/HelloWorld/hellolibrary/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/HelloWorld/hellolibrary/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayvazj/gradle-androlate-plugin/1b720545ef1330dec2ff1d30c7b7e6a04008b36c/examples/HelloWorld/hellolibrary/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/HelloWorld/hellolibrary/src/main/res/values-es/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Hola Biblioteca 3 | 4 | -------------------------------------------------------------------------------- /examples/HelloWorld/hellolibrary/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Hello Library 3 | 4 | -------------------------------------------------------------------------------- /examples/HelloWorld/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':hellolibrary' 2 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | VERSION_NAME=0.3 2 | GROUP=com.github.ayvazj.gradle.plugins.androlate 3 | 4 | POM_DESCRIPTION=Translate your string resources using Google Translate. 5 | POM_URL=https://github.com/ayvazj/gradle-androlate-plugin/ 6 | POM_SCM_URL=https://github.com/ayvazj/gradle-androlate-plugin/ 7 | POM_SCM_CONNECTION=scm:git@github.com/ayvazj/gradle-androlate-plugin.git 8 | POM_SCM_DEV_CONNECTION=scm:git@github.com:ayvazj/gradle-androlate-plugin.git 9 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 10 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 11 | POM_LICENCE_DIST=repo 12 | POM_DEVELOPER_ID=ayvazj 13 | POM_DEVELOPER_NAME=James Ayvaz 14 | POM_INCEPTION_YEAR=2015 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayvazj/gradle-androlate-plugin/1b720545ef1330dec2ff1d30c7b7e6a04008b36c/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Aug 15 11:22:12 CEST 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /local.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'androlate' 2 | 3 | -------------------------------------------------------------------------------- /src/main/groovy/com/github/ayvazj/gradle/plugins/androlate/Androlate.groovy: -------------------------------------------------------------------------------- 1 | package com.github.ayvazj.gradle.plugins.androlate 2 | 3 | import groovy.xml.Namespace 4 | 5 | 6 | class Androlate { 7 | public static final Namespace NAMESPACE = new Namespace("http://com.github.androlate", 'xandrolate') 8 | } 9 | -------------------------------------------------------------------------------- /src/main/groovy/com/github/ayvazj/gradle/plugins/androlate/AndrolateBaseElement.groovy: -------------------------------------------------------------------------------- 1 | package com.github.ayvazj.gradle.plugins.androlate 2 | 3 | import com.google.api.services.translate.model.TranslationsResource 4 | import org.w3c.dom.Element 5 | 6 | 7 | abstract class AndrolateBaseElement { 8 | def Element node = null 9 | def md5txt = null 10 | 11 | public AndrolateBaseElement(Element node) { 12 | this.node = node 13 | } 14 | 15 | def public String name() { 16 | return this.node.getAttribute('name') 17 | } 18 | 19 | def public String md5() { 20 | if (this.node && !this.md5txt) { 21 | this.md5txt = AndrolateUtils.md5sum(this.node.getTextContent()) 22 | } 23 | return this.md5txt 24 | } 25 | 26 | /** 27 | * Add / Update the androlate:md5 attribute on the node 28 | */ 29 | def public void updateMd5() { 30 | if (this.node) { 31 | this.node.setAttributeNS(Androlate.NAMESPACE.uri, "${Androlate.NAMESPACE.prefix}:md5", md5()) 32 | this.node.setAttribute('name', this.node.getAttribute('name')) 33 | } 34 | } 35 | 36 | def public boolean isTranslatable() { 37 | // If translatable is false then it isn't - otherwise it is 38 | return this.node.getAttribute('translatable') != "false" 39 | } 40 | 41 | def public boolean isDirty() { 42 | if (this.node) { 43 | def md5attr = this.node.getAttributeNS(Androlate.NAMESPACE.uri, 'md5') 44 | return md5() != md5attr 45 | } 46 | return true 47 | } 48 | 49 | def public String[] text() { 50 | if (this.node) { 51 | return [AndrolateUtils.getMixedContent(this.node)] 52 | } 53 | return null 54 | } 55 | 56 | /** 57 | * Used to query how many strings this element has 58 | * @return 59 | */ 60 | def public int getTextCount() { 61 | return 1 62 | } 63 | 64 | /** 65 | * Update the destination 66 | * @param destxml 67 | * @param translatedText 68 | * @return 69 | */ 70 | def public void updateDestXml(Element destxml, List translatedResources) { 71 | if ("string".equals(this.node.getNodeName())) { 72 | def string_name = this.node.getAttribute('name') 73 | def existing = null 74 | def string_elems = destxml.getElementsByTagName('string') 75 | if (string_elems && string_elems.length > 0) { 76 | existing = string_elems.findAll { Element deststring -> deststring.getAttribute('name') == string_name } 77 | } 78 | 79 | if (existing) { 80 | existing.each { Element existstring -> 81 | existstring.setNodeValue(AndrolateUtils.googleTranslateResolve(translatedResources[0].getTranslatedText())) 82 | } 83 | } else { 84 | def Element newelem = destxml.getOwnerDocument().createElement('string') 85 | newelem.setAttribute('name', string_name) 86 | if (this.node.hasChildNodes() && this.node.getFirstChild().getNodeType() == org.w3c.dom.Node.CDATA_SECTION_NODE) { 87 | def cdata = destxml.getOwnerDocument().createCDATASection(AndrolateUtils.googleTranslateResolve(translatedResources[0].getTranslatedText())) 88 | newelem.appendChild(cdata) 89 | } else { 90 | def alltext = AndrolateUtils.googleTranslateResolve(translatedResources[0].getTranslatedText()) 91 | def Element mixedNodes = null 92 | 93 | try { 94 | mixedNodes = AndrolateUtils.getMixedNodes(destxml, alltext) 95 | } 96 | catch(Exception ex) { 97 | System.err << "Unable to translate string: name=${string_name}" 98 | System.err << ex 99 | } 100 | if (mixedNodes) { 101 | mixedNodes.getChildNodes().each { node -> 102 | def importedNode = destxml.getOwnerDocument().importNode(node, true) 103 | newelem.appendChild(importedNode) 104 | } 105 | } 106 | else { 107 | System.err << "Unable to translate string: name=${string_name}" 108 | } 109 | } 110 | 111 | destxml.appendChild(newelem) 112 | 113 | } 114 | } 115 | return 116 | } 117 | 118 | def public static newInstance(Element elem) { 119 | if ('string'.equals(elem.getNodeName())) { 120 | return new AndrolateStringElement(elem) 121 | } else if ('string-array'.equals(elem.getNodeName())) { 122 | return new AndrolateStringArrayElement(elem) 123 | } 124 | return null 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/main/groovy/com/github/ayvazj/gradle/plugins/androlate/AndrolateExportAppleTask.groovy: -------------------------------------------------------------------------------- 1 | package com.github.ayvazj.gradle.plugins.androlate 2 | 3 | import groovy.xml.DOMBuilder 4 | import org.gradle.api.DefaultTask 5 | import org.gradle.api.GradleScriptException 6 | import org.gradle.api.tasks.TaskAction 7 | import org.w3c.dom.Element 8 | 9 | class AndrolateExportAppleTask extends DefaultTask { 10 | 11 | AndrolatePluginExtension androlate 12 | 13 | 14 | AndrolateExportAppleTask() { 15 | super() 16 | this.description = 'Export string resources to iOS / OS X format' 17 | } 18 | 19 | void extract_strings(File file, data) { 20 | def dir = file.getParentFile() 21 | def dirname = dir.getName() 22 | def resource_qualifiers = AndrolateUtils.getResourceQualifiers(dirname) 23 | 24 | def srcparser 25 | 26 | if (file.exists()) { 27 | def destreader = new FileReader(file) 28 | try { 29 | srcparser = DOMBuilder.newInstance(false, true).parse(destreader) 30 | } 31 | catch (Exception e) { 32 | throw new GradleScriptException("Error parsing ${destfile}", e) 33 | } 34 | } 35 | 36 | def Element srcxml = srcparser.documentElement 37 | 38 | // ignore XML files that are not resource files 39 | if (!srcxml.getTagName().equals('resources')) { 40 | return 41 | } 42 | 43 | def stringElems = srcxml.getElementsByTagName('string') 44 | if (!stringElems || stringElems.length == 0) { 45 | return; 46 | } 47 | 48 | stringElems.each { Element string -> 49 | def string_name = string.getAttribute('name') 50 | def string_text = AndrolateUtils.getMixedContent(string) 51 | 52 | if (!data.containsKey(string_name)) { 53 | data[string_name] = [:] 54 | } 55 | 56 | if (resource_qualifiers.size() == 0) { 57 | data[string_name]["__default__"] = string_text 58 | } else { 59 | for (qual in resource_qualifiers) { 60 | data[string_name][qual] = string_text 61 | } 62 | } 63 | } 64 | } 65 | 66 | def appendLocalizableStrings(fileName, string_text, string_translation) { 67 | def file = new File(fileName) 68 | if (file.getParentFile()) { 69 | file.getParentFile().mkdirs() 70 | } 71 | 72 | if (!file.exists() && !file.createNewFile()) { 73 | throw new GradleScriptException("Unable to create file '${fileName}", null) 74 | } 75 | 76 | file.append("\"" + AndrolateUtils.convertToAppleFormatting(string_text) + "\" = \"" + AndrolateUtils.convertToAppleFormatting(string_translation) + "\"" + System.getProperty("line.separator")) 77 | } 78 | 79 | @TaskAction 80 | def export_apple() { 81 | androlate = project.androlate 82 | println('Exporting String resources') 83 | println(' Default Language : ' + androlate.defaultLanguage) 84 | 85 | 86 | def data = [:] // data is a map of files and strings 87 | // TODO revist to find a more optimal way of locating strings.xml 88 | project.fileTree(dir: 'src', include: '**/*.xml').each { File file -> 89 | extract_strings(file, data) 90 | } 91 | 92 | def fileName = 'export/apple/Localizable.strings' 93 | def file = new File(fileName) 94 | if (file.getParentFile()) { 95 | file.getParentFile().mkdirs() 96 | } 97 | 98 | if (!file.exists() && !file.createNewFile()) { 99 | throw new GradleScriptException("Unable to create file '${fileName}", null) 100 | } 101 | 102 | data.each { string_name, qualifiers -> 103 | // each resource type (i.e. values-* ) 104 | qualifiers.each { qualkey, qualval -> 105 | if ("__default__".equals(qualkey)) { 106 | appendLocalizableStrings("export/apple/Localizable.strings", data[string_name]['__default__'], data[string_name]["__default__"]) 107 | } else { 108 | appendLocalizableStrings("export/apple/${qualkey}/Localizable.strings", data[string_name]['__default__'], data[string_name][qualkey]) 109 | } 110 | } 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/main/groovy/com/github/ayvazj/gradle/plugins/androlate/AndrolateExportExcelTask.groovy: -------------------------------------------------------------------------------- 1 | package com.github.ayvazj.gradle.plugins.androlate 2 | 3 | import org.gradle.api.DefaultTask 4 | import org.gradle.api.GradleScriptException 5 | import org.gradle.api.tasks.TaskAction 6 | 7 | class AndrolateExportExcelTask extends DefaultTask { 8 | 9 | AndrolatePluginExtension androlate 10 | 11 | 12 | AndrolateExportExcelTask() { 13 | super() 14 | this.description = 'Export string resources to to MS Excel spreadsheet' 15 | } 16 | 17 | void extract_strings(File file, data) { 18 | def dir = file.getParentFile() 19 | def dirname = dir.getName() 20 | def resource_name = AndrolateUtils.getResourceName(dirname) 21 | def resource_qualifiers = AndrolateUtils.getResourceQualifiers(dirname) 22 | 23 | def srcparser = new XmlParser() 24 | def srcxml = srcparser.parse(file) 25 | 26 | // ignore XML files that are not resource files 27 | if (!srcxml.name().equals('resources')) { 28 | return 29 | } 30 | 31 | def stringElems = srcxml.string 32 | if (!stringElems || stringElems.size() == 0) { 33 | return; 34 | } 35 | 36 | stringElems.each { string -> 37 | def string_name = string.'@name' 38 | def string_text = string.text() 39 | if (!data.containsKey(resource_name)) { 40 | data[resource_name] = [:] 41 | } 42 | if (!data[resource_name].containsKey("__default__")) { 43 | data[resource_name]["__default__"] = [:] 44 | } else { 45 | for (qual in resource_qualifiers) { 46 | if (!data[resource_name].containsKey(qual)) { 47 | data[resource_name][qual] = [:] 48 | } 49 | } 50 | } 51 | 52 | if (resource_qualifiers.size() == 0) { 53 | data[resource_name]["__default__"][string_name] = string_text 54 | } else { 55 | for (qual in resource_qualifiers) { 56 | data[resource_name][qual][string_name] = string_text 57 | } 58 | } 59 | } 60 | } 61 | 62 | @TaskAction 63 | def export_excel() { 64 | androlate = project.androlate 65 | println('Exporting String resources') 66 | println(' Default Language : ' + androlate.defaultLanguage) 67 | 68 | 69 | def data = [:] // data is a map of files and strings 70 | // TODO revist to find a more optimal way of locating strings.xml 71 | project.fileTree(dir: 'src', include: '**/*.xml').each { File file -> 72 | extract_strings(file, data) 73 | } 74 | 75 | def fileName = 'export/xls/androlate.xls' 76 | def file = new File(fileName) 77 | if (file.getParentFile()) { 78 | file.getParentFile().mkdirs() 79 | } 80 | 81 | if (!file.exists() && !file.createNewFile()) { 82 | throw new GradleScriptException("Unable to create file '${fileName}", null) 83 | } 84 | 85 | // pivot the data so we can fill the table 86 | def tableData = [:] 87 | data.each { resource_name, qualifiers -> 88 | // each resource type (i.e. values-* ) 89 | 90 | qualifiers.each { qualstr, values -> 91 | values.each { strkey, strval -> 92 | // keep track of the keys we see 93 | 94 | if (!tableData.containsKey(strkey)) { 95 | tableData[strkey] = [:] 96 | } 97 | tableData[strkey][qualstr] = strval 98 | } 99 | } 100 | } 101 | 102 | // keep the languages in a sorted list since the keys may be in different orders 103 | def langkeys = [] 104 | tableData.each { strkey, values -> 105 | values.each { key, value -> 106 | if (!langkeys.contains(key)) { 107 | langkeys.add(key) 108 | } 109 | } 110 | } 111 | 112 | //println(tableData.toString().replace("[", "\n\t[")) 113 | def writer = new FileWriter(fileName) 114 | def xml = new groovy.xml.MarkupBuilder(writer) 115 | xml.setDoubleQuotes(true) 116 | xml.mkp.xmlDeclaration(version: "1.0", encoding: "utf-8") 117 | xml."ss:Workbook"("xmlns:ss": "urn:schemas-microsoft-com:office:spreadsheet") { 118 | "ss:Worksheet"("ss:Name": "TODO Sheet name") { 119 | "ss:Table"() { 120 | "ss:Row"() { 121 | "ss:Cell"() { 122 | "ss:Data"("ss:Type": "String", "STRING") 123 | } 124 | langkeys.each { langkey -> 125 | "ss:Cell"() { 126 | "ss:Data"("ss:Type": "String", "${langkey}") 127 | } 128 | } 129 | } 130 | 131 | tableData.each { strkey, values -> 132 | "ss:Row"() { 133 | "ss:Cell"() { 134 | "ss:Data"("ss:Type": "String", strkey) 135 | } 136 | langkeys.each { langkey -> 137 | values.each { valkey, valval -> 138 | if (valkey == langkey) { 139 | "ss:Cell"() { 140 | "ss:Data"("ss:Type": "String", valval) 141 | } 142 | } 143 | } 144 | } 145 | } 146 | } 147 | } 148 | } 149 | } 150 | } 151 | 152 | // write the list of string data to XML files in Android resource file format 153 | def write_missing_xlate(missing_list) { 154 | missing_list.each { item -> 155 | def resource_name = item["resource_name"] 156 | def qualstr_xlate = item["qualstr_xlate"] 157 | def dirname = "./xportlate/${resource_name}-${qualstr_xlate}" 158 | new File(dirname).mkdirs() 159 | def fileName = "${dirname}/strings.xml" 160 | 161 | def writer = new FileWriter(fileName) 162 | def xml = new groovy.xml.MarkupBuilder(writer) 163 | xml.setDoubleQuotes(true) 164 | xml.mkp.xmlDeclaration(version: "1.0", encoding: "utf-8") 165 | xml.resources() { 166 | missing_list.each { item_nested -> 167 | if (item_nested["resource_name"] == resource_name && item_nested["qualstr_xlate"] == qualstr_xlate) { 168 | def strkey = item_nested["strkey"] 169 | def strval = item_nested["strval"] 170 | string(name: strkey, strval) 171 | } 172 | } 173 | } 174 | } 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /src/main/groovy/com/github/ayvazj/gradle/plugins/androlate/AndrolatePlugin.groovy: -------------------------------------------------------------------------------- 1 | package com.github.ayvazj.gradle.plugins.androlate 2 | 3 | import org.gradle.api.Plugin 4 | import org.gradle.api.Project 5 | 6 | class AndrolatePlugin implements Plugin { 7 | 8 | final static String GROUP_NAME = 'Androlate' 9 | 10 | void apply(Project project) { 11 | applyExtensions(project) 12 | applyTasks(project) 13 | } 14 | 15 | static void applyExtensions(final Project project) { 16 | project.extensions.create('androlate', AndrolatePluginExtension, project) 17 | } 18 | 19 | static void applyTasks(final Project project) { 20 | project.task('androlate', type: AndrolateTranslateTask, group: GROUP_NAME) 21 | project.task('androlate-export-apple', type: AndrolateExportAppleTask, group: GROUP_NAME) 22 | // project.task('androlate-export-xls', type: AndrolateExportExcelTask, group: GROUP_NAME) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/groovy/com/github/ayvazj/gradle/plugins/androlate/AndrolatePluginExtension.groovy: -------------------------------------------------------------------------------- 1 | package com.github.ayvazj.gradle.plugins.androlate 2 | 3 | import org.gradle.api.Project 4 | 5 | class AndrolatePluginExtension { 6 | def String defaultLanguage 7 | def targetLanguages 8 | def String apiKey 9 | def String appName 10 | def boolean backup 11 | private final Project project 12 | 13 | public AndrolatePluginExtension(Project project) { 14 | this.project = project 15 | this.defaultLanguage = 'en' 16 | this.targetLanguages = [] 17 | this.apiKey = '' 18 | this.backup = true 19 | this.appName = null 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/groovy/com/github/ayvazj/gradle/plugins/androlate/AndrolateStringArrayElement.groovy: -------------------------------------------------------------------------------- 1 | package com.github.ayvazj.gradle.plugins.androlate 2 | 3 | import com.google.api.services.translate.model.TranslationsResource 4 | import org.w3c.dom.Element 5 | 6 | 7 | class AndrolateStringArrayElement extends AndrolateBaseElement { 8 | AndrolateStringArrayElement(Element node) { 9 | super(node) 10 | } 11 | 12 | @Override 13 | def public String md5() { 14 | if (this.node && !this.md5txt) { 15 | def item_concat = '' 16 | def item_elems = this.node.getElementsByTagName('item') 17 | if (item_elems && item_elems.length > 0) { 18 | item_elems.each { Element item -> 19 | item_concat += "${item.getTextContent()}" 20 | } 21 | } 22 | this.md5txt = AndrolateUtils.md5sum(item_concat) 23 | } 24 | return this.md5txt 25 | } 26 | 27 | @Override 28 | def public String[] text() { 29 | if (this.node) { 30 | def result = [] 31 | def item_elems = this.node.getElementsByTagName('item') 32 | if (item_elems && item_elems.length > 0) { 33 | item_elems.each { Element item -> 34 | result.add("${item.getTextContent()}") 35 | } 36 | } 37 | return result 38 | } 39 | return null 40 | } 41 | 42 | /** 43 | * Used to query how many strings this element has 44 | * @return 45 | */ 46 | @Override 47 | def public int getTextCount() { 48 | if (this.node) { 49 | def item_elems = this.node.getElementsByTagName('item') 50 | if (item_elems && item_elems.length > 0) { 51 | return item_elems.length 52 | } 53 | } 54 | return 0 55 | } 56 | 57 | @Override 58 | def public void updateDestXml(Element destxml, List translatedResources) { 59 | if ("string-array".equals(this.node.getNodeName())) { 60 | def string_name = this.node.getAttribute('name') 61 | 62 | def existing = null 63 | def stringarray_elems = destxml.getElementsByTagName('string-array') 64 | if (stringarray_elems && stringarray_elems.length > 0) { 65 | existing = stringarray_elems.findAll { Element deststring -> deststring.getAttribute('name') == string_name } 66 | } 67 | 68 | if (existing) { 69 | // updating string arrays are tricky, so just replace them for now 70 | existing.each { Element exist -> 71 | destxml.removeChild(exist) 72 | } 73 | } 74 | 75 | def Element newelem = destxml.getOwnerDocument().createElement('string-array') 76 | newelem.setAttribute('name', string_name) 77 | 78 | translatedResources.each { tr -> 79 | def alltext = AndrolateUtils.googleTranslateResolve(tr.getTranslatedText()) 80 | def Element mixedNodes = AndrolateUtils.getMixedNodes(destxml, alltext) 81 | 82 | def Element newItem = destxml.getOwnerDocument().createElement('item') 83 | mixedNodes.getChildNodes().each { node -> 84 | def importedNode = destxml.getOwnerDocument().importNode(node, true) 85 | newItem.appendChild(importedNode) 86 | } 87 | newelem.appendChild(newItem) 88 | } 89 | destxml.appendChild(newelem) 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/groovy/com/github/ayvazj/gradle/plugins/androlate/AndrolateStringElement.groovy: -------------------------------------------------------------------------------- 1 | package com.github.ayvazj.gradle.plugins.androlate 2 | 3 | import org.w3c.dom.Element 4 | 5 | 6 | class AndrolateStringElement extends AndrolateBaseElement { 7 | AndrolateStringElement(Element node) { 8 | super(node) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/groovy/com/github/ayvazj/gradle/plugins/androlate/AndrolateTranslateTask.groovy: -------------------------------------------------------------------------------- 1 | package com.github.ayvazj.gradle.plugins.androlate 2 | 3 | import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport 4 | import com.google.api.client.http.javanet.NetHttpTransport 5 | import com.google.api.client.json.JsonFactory 6 | import com.google.api.client.json.jackson2.JacksonFactory 7 | import com.google.api.services.translate.Translate 8 | import com.google.api.services.translate.model.TranslationsResource 9 | import groovy.xml.DOMBuilder 10 | import groovy.xml.Namespace 11 | import groovy.xml.XmlUtil 12 | import org.apache.commons.lang.StringEscapeUtils 13 | import org.gradle.api.DefaultTask 14 | import org.gradle.api.GradleScriptException 15 | import org.gradle.api.internal.tasks.options.Option 16 | import org.gradle.api.logging.LogLevel 17 | import org.gradle.api.tasks.TaskAction 18 | import org.w3c.dom.Element 19 | 20 | class AndrolateTranslateTask extends DefaultTask { 21 | 22 | /** Global instance of the HTTP transport. */ 23 | NetHttpTransport httpTransport 24 | 25 | /** Global instance of the JSON factory. */ 26 | JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance() 27 | 28 | /** Global instance of Androlate Extension */ 29 | AndrolatePluginExtension androlate 30 | 31 | /** Global instance of Translate client */ 32 | Translate translateClient 33 | 34 | @Option(option = "force", description = "Force translation even for non-dirty strings.") 35 | boolean force = false 36 | 37 | 38 | AndrolateTranslateTask() { 39 | this.description = 'Translates the default string resources using Google Translate' 40 | this.androlate = project.androlate 41 | def httpTransport = GoogleNetHttpTransport.newTrustedTransport() 42 | // set up global Translate instance 43 | this.translateClient = new Translate.Builder( 44 | httpTransport, 45 | JSON_FACTORY, 46 | null 47 | ).setApplicationName("${androlate.appName}").build() 48 | } 49 | 50 | /** 51 | * Send given set of string for translation 52 | * @param xstrings the strings to be translated 53 | * @param xlated_strings the translated strings are returned here 54 | * @param lang the targetLanguage 55 | */ 56 | void executeTranslationRequest(List xstrings, List xlated_strings, String lang) { 57 | Translate.Translations.List translateRequest = this.translateClient.translations().list( 58 | xstrings, 59 | "${lang}" 60 | ) 61 | translateRequest.setFormat('html') 62 | translateRequest.setKey("${androlate.apiKey}") 63 | def translateResponse = translateRequest.execute() 64 | xlated_strings.addAll(translateResponse.getTranslations()) 65 | } 66 | 67 | /** 68 | * Google translate requires requests be < 2K for GET and <5K for post. This method should conver the list 69 | * of strings to be translated into allowable chunks, send them for translation, then assemble the results 70 | * 71 | * @param stringsdirty the strings to be translated 72 | * @param xlated_strings the translated strings returned from Google 73 | * @param lang 74 | */ 75 | void getChunkedTranslations(List elements, List xlated_strings, String lang) { 76 | 77 | List xstrings = new ArrayList(); 78 | 79 | // read all strings into a map [ dirname => [ name, value ]] 80 | def charcount = 0 81 | elements.each { elem -> 82 | def elem_texts = elem.text() 83 | if (elem_texts) { 84 | elem_texts.each { string_text -> 85 | def procstring = AndrolateUtils.googleTranslateEscape(string_text, lang) 86 | // request has to be less than 2K GET or 5K POST 87 | if (charcount < 2048) { 88 | xstrings.add(procstring) 89 | charcount += StringEscapeUtils.escapeHtml(procstring).length() + 3 90 | } else { 91 | executeTranslationRequest(xstrings, xlated_strings, lang) 92 | xstrings.clear() 93 | xstrings.add(procstring) 94 | charcount += procstring.length() 95 | } 96 | } 97 | } 98 | } 99 | 100 | if (xstrings.size() > 0) { 101 | executeTranslationRequest(xstrings, xlated_strings, lang) 102 | } 103 | } 104 | 105 | /** 106 | * Performs the androlate translation process on an individual resource file 107 | */ 108 | void androlateFile(File file, boolean force) { 109 | 110 | def dir = file.getParentFile() 111 | def dirname = dir.getName() 112 | def resource_qualifiers = AndrolateUtils.getResourceQualifiers(dirname) 113 | 114 | // ignore XML files that are not in the default resource directory 115 | if (resource_qualifiers && resource_qualifiers.size() > 0) { 116 | return; 117 | } 118 | 119 | def srcreader = new FileReader(file) 120 | def srcparser 121 | try { 122 | srcparser = DOMBuilder.newInstance(false, true).parse(srcreader) 123 | } 124 | catch (Exception e) { 125 | throw new GradleScriptException("Error parsing ${file.getName()}", e) 126 | } 127 | 128 | if (!srcparser) { 129 | return 130 | } 131 | 132 | def Element srcxml = srcparser.documentElement 133 | // ignore XML files that are not resource files 134 | if (!srcxml.getNodeName().equals('resources')) { 135 | return 136 | } 137 | 138 | def List stringsdirty = new ArrayList() 139 | def children = srcxml.getChildNodes() 140 | if (children && children.length) { 141 | children.each { org.w3c.dom.Node child -> 142 | if (child.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) { 143 | def Element elem = child as org.w3c.dom.Element 144 | if ("string".equals(elem.getTagName()) || "string-array".equals(elem.getTagName())) { 145 | 146 | AndrolateBaseElement abelem = AndrolateBaseElement.newInstance(child) 147 | boolean dirty = abelem.isDirty() || force 148 | 149 | if (dirty && abelem.isTranslatable()) { 150 | abelem.updateMd5() 151 | stringsdirty.add(abelem) 152 | } 153 | } 154 | } 155 | } 156 | } 157 | 158 | if (!stringsdirty || stringsdirty.size() == 0) { 159 | return; 160 | } 161 | 162 | // Add the md5 sum to the sources to avoid resending unchanged strings 163 | srcxml.setAttribute("xmlns:${Androlate.NAMESPACE.prefix}", Androlate.NAMESPACE.getUri().toString()) 164 | 165 | if (androlate.backup) { 166 | // save the modified source file 167 | def backfn = AndrolateUtils.findBackupFilename(file) 168 | if (!backfn) { 169 | throw new GradleScriptException("Unable to create backup file") 170 | } 171 | 172 | File backFile = new File(backfn) 173 | logger.log(LogLevel.INFO, "Renaming ${file.getName()} to ${backFile.getName()}") 174 | 175 | file.renameTo(backfn) 176 | } 177 | 178 | def outwriter = new FileWriter(file.getPath()) 179 | def fos = new FileOutputStream(file.getPath()); 180 | def osw = new OutputStreamWriter(fos,"UTF-8"); 181 | XmlUtil.serialize(srcxml, outwriter) 182 | osw.close() 183 | 184 | androlate.targetLanguages.each { lang -> 185 | def destdir = new File("${dir.path}-${lang}") 186 | def destfile = new File("${destdir.path}/${file.getName()}") 187 | 188 | destdir.mkdirs() 189 | def destparser 190 | 191 | if (destfile.exists()) { 192 | def destreader = new FileReader(destfile) 193 | try { 194 | destparser = DOMBuilder.newInstance(false, true).parse(destreader) 195 | } 196 | catch (Exception e) { 197 | throw new GradleScriptException("Error parsing ${destfile}", e) 198 | } 199 | } else { 200 | // create the destination document 201 | try { 202 | destparser = DOMBuilder.newInstance(false, true).parseText('''\n''') 203 | } 204 | catch (Exception e) { 205 | throw new GradleScriptException("Error parsing ${destfile}", e) 206 | } 207 | } 208 | 209 | def destxml = destparser.documentElement 210 | 211 | List xlated_strings = new ArrayList() 212 | getChunkedTranslations(stringsdirty, xlated_strings, lang) 213 | 214 | def i = 0 215 | def pos = 0 216 | while (i < stringsdirty.size()) { 217 | def incby = stringsdirty[i].getTextCount() 218 | if (pos <= xlated_strings.size()) { 219 | stringsdirty[i].updateDestXml(destxml, xlated_strings[pos..<(pos + incby)]) 220 | } 221 | i++ 222 | pos += incby 223 | } 224 | 225 | //Save File 226 | def destfos = new FileOutputStream(destfile); 227 | def destosw = new OutputStreamWriter(destfos,"UTF-8"); 228 | XmlUtil.serialize(destxml, destosw) 229 | destosw.close() 230 | } 231 | 232 | } 233 | 234 | @TaskAction 235 | void androlate() { 236 | if (!androlate.apiKey) { 237 | throw new GradleScriptException("androlate.apiKey is not defined", null) 238 | } 239 | 240 | if (!androlate.appName) { 241 | throw new GradleScriptException("androlate.appName is not defined", null) 242 | } 243 | 244 | 245 | println(' Default Language : ' + androlate.defaultLanguage) 246 | 247 | // TODO revist to find a more optimal way of locating strings.xml 248 | project.fileTree(dir: 'src', include: '**/*.xml').each { File file -> 249 | androlateFile(file, force) 250 | } 251 | } 252 | } 253 | -------------------------------------------------------------------------------- /src/main/groovy/com/github/ayvazj/gradle/plugins/androlate/AndrolateUtils.groovy: -------------------------------------------------------------------------------- 1 | package com.github.ayvazj.gradle.plugins.androlate 2 | 3 | import groovy.xml.DOMBuilder 4 | import groovy.xml.XmlUtil 5 | import org.gradle.api.GradleScriptException 6 | import org.w3c.dom.Document 7 | import org.w3c.dom.DocumentFragment 8 | import org.w3c.dom.Element 9 | import org.w3c.dom.Node 10 | 11 | import java.security.MessageDigest 12 | 13 | 14 | class AndrolateUtils { 15 | 16 | def private static final REPLACE_MAP = [ 17 | "\\n": "axlate_N", 18 | "\\t": "axlate_T", 19 | "\\r": "axlate_R", 20 | "%" : "axlate_percent", 21 | "\$" : "axlate_dollar" 22 | ] 23 | 24 | def private static final IOS_REPLACE_MAP = [ 25 | "\\%.*?s": "%@" 26 | ] 27 | 28 | def public static getResourceName(dirname) { dirname.tokenize("-")[0] } 29 | 30 | def public static getResourceQualifiers(dirname) { 31 | def tokens = dirname.tokenize("-") 32 | if (tokens.size() > 1) { 33 | return tokens[1..-1] 34 | } 35 | return [] 36 | } 37 | 38 | /** 39 | * MD5SUM 40 | */ 41 | def public static String md5sum(String s) { 42 | MessageDigest digest = MessageDigest.getInstance("MD5") 43 | digest.update(s.bytes); 44 | return new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0') 45 | } 46 | 47 | /** 48 | * Google translate takes some liberties with formatting for the sake of 49 | * meaningful human translations, we don't need things to be that smart 50 | * so these two methods attempt to modify prevent Google' NLP from 51 | * modifying the string too much 52 | * 53 | * @param instr 54 | * @param lang 55 | * @return 56 | */ 57 | def public static String googleTranslateEscape(String instr, String lang) { 58 | String result = instr 59 | REPLACE_MAP.each { String k, String v -> 60 | result = result.replace(k, "${v}") 61 | } 62 | result = "" + result + "" 63 | return result 64 | } 65 | 66 | def public static String googleTranslateResolve(String instr) { 67 | String result = replaceLast(instr, "", "") 68 | REPLACE_MAP.each { k, v -> 69 | result = result.replace(" ${v} ", k) 70 | result = result.replace(v, k) 71 | } 72 | result = result.replaceFirst("\\", "") 73 | return result 74 | } 75 | 76 | def private static String replaceLast(String string, String substring, String replacement) { 77 | int index = string.lastIndexOf(substring); 78 | if (index == -1) 79 | return string; 80 | return string.substring(0, index) + replacement 81 | +string.substring(index + substring.length()); 82 | } 83 | 84 | /** 85 | * Try to convert Java/Android string formatting to Mac/iOS style 86 | * @param instr 87 | * @return 88 | */ 89 | def public static String convertToAppleFormatting(String instr) { 90 | String result = instr 91 | IOS_REPLACE_MAP.each { k, v -> 92 | result = result.replaceAll(k, v) 93 | } 94 | return result 95 | } 96 | 97 | def public static String findBackupFilename(File file) { 98 | def (String basename, String ext) = file.getName().split("\\.(?=[^\\.]+\$)"); 99 | def i = '' 100 | def result = null 101 | while (true) { 102 | result = file.getParentFile().getPath() + System.getProperty("file.separator") + basename + ".bak" + i 103 | def File resFile = new File(result) 104 | if (!resFile.exists()) { 105 | return result 106 | } 107 | if (!i) { 108 | i = 1 109 | } else { 110 | i++ 111 | } 112 | } 113 | return result 114 | } 115 | 116 | /** 117 | * Returns a string representenation of all the textContent including mixed content 118 | * @param elem 119 | * @return 120 | */ 121 | def public static String getMixedContent(Node node) { 122 | if (node.hasChildNodes()) { 123 | def result = '' 124 | def children = node.getChildNodes() 125 | if (children && children.length) { 126 | children.each { org.w3c.dom.Node child -> 127 | if (child.getNodeType() == Node.ELEMENT_NODE) { 128 | def xmlOutput = new StringWriter() 129 | XmlUtil.serialize(child, xmlOutput) 130 | result += xmlOutput.toString().replaceAll("<\\?.*\\?>", "").trim() 131 | } else { 132 | result += child.getNodeValue() 133 | } 134 | } 135 | } 136 | return result 137 | } 138 | return node.getNodeValue() 139 | } 140 | 141 | def public static Element getMixedNodes(Element element, String s) { 142 | 143 | def parser = null 144 | 145 | // create the destination document 146 | try { 147 | println("s => [${s}]"); 148 | parser = DOMBuilder.newInstance(false, true).parseText("\n${s}") 149 | } 150 | catch (Exception e) { 151 | throw new GradleScriptException("Error parsing getMixedNodes", e) 152 | } 153 | 154 | if (parser == null) { 155 | return null 156 | } 157 | 158 | return parser.documentElement 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/gradle-plugins/androlate.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.github.ayvazj.gradle.plugins.androlate.AndrolatePlugin 2 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/gradle-plugins/com.github.ayvazj.plugins.androlate.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.github.ayvazj.gradle.plugins.androlate.AndrolatePlugin 2 | -------------------------------------------------------------------------------- /src/test/groovy/com/github/ayvazj/gradle/plugins/androlate/AndrolatePluginTest.groovy: -------------------------------------------------------------------------------- 1 | package com.github.ayvazj.gradle.plugins.androlate 2 | 3 | 4 | class AndrolatePluginTest { 5 | } 6 | --------------------------------------------------------------------------------