├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── po │ ├── fr.po │ ├── fr_CH.po │ └── ru.po ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── hulab │ │ └── gettext │ │ └── example │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── hulab │ │ │ └── gettext │ │ │ └── example │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── hulab │ └── gettext │ └── example │ └── ExampleUnitTest.java ├── build.gradle ├── gettext ├── .gitignore ├── build.gradle ├── gradle.properties ├── local.properties ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── hulab │ │ └── gettext │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── hulab │ │ │ └── gettext │ │ │ ├── CFormatter.java │ │ │ ├── Messages.java │ │ │ └── PO.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── hulab │ └── gettext │ └── ExampleUnitTest.java ├── gradle-plugin ├── .gitignore ├── build.gradle ├── gradle.properties ├── settings.gradle └── src │ ├── main │ ├── AndroidManifest.xml │ ├── groovy │ │ └── com │ │ │ └── hulab │ │ │ └── gradle │ │ │ └── GettextAndroid.groovy │ └── resources │ │ └── META-INF │ │ └── gradle-plugins │ │ └── com.hulab.gradle.gettext-android.properties │ ├── scripts.zip │ └── scripts │ ├── Messages.java.tmpl │ ├── po-compile-all │ └── po-compile.py ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── pom.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | .idea 11 | /gettext/gradlew.bat 12 | gettext/gradlew 13 | gettext/gradlew.bat 14 | gradle-plugin/gradle/ 15 | gradle-plugin/gradlew 16 | gradle-plugin/gradlew.bat 17 | private_key_sender.asc 18 | public_key_sender.asc 19 | -------------------------------------------------------------------------------- /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 {2017} {Hulab} 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Gettext-Android 2 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [ ![Download](https://api.bintray.com/packages/nebneb/Gettext-Android/gettext/images/download.svg) ](https://bintray.com/nebneb/Gettext-Android/gettext/_latestVersion) 3 | 4 | Gettext for Android allows you to use common po files to an Android project. 5 | 6 | # Installation 7 | 8 | First, put your po files at the root of your project, at the same level as your src/ folder. 9 | 10 | ``` 11 | my-project/ 12 | ├── src/ 13 | ├── po/ 14 | │ ├── en.po 15 | │ ├── en_US.po 16 | │ ├── fr.po 17 | │ ├── fr_CH.po 18 | │ ├── ru.po 19 | │ └ ... 20 | └ ... 21 | ``` 22 | 23 | Then, add the following to your `build.gradle` file: 24 | 25 | ```groovy 26 | buildscript { 27 | repositories { 28 | jcenter() 29 | } 30 | 31 | dependencies { 32 | // Classpath dependency for gettext gradle plugin 33 | classpath "gradle.plugin.com.hulab.gradle:gradle-plugin:1.0.0" 34 | } 35 | } 36 | 37 | 38 | dependencies { 39 | 40 | // Gettext library dependency 41 | implementation 'com.hulab.android:gettext:1.0.1' 42 | } 43 | 44 | // Apply plugin 45 | apply plugin: "com.hulab.gradle.gettext-android" 46 | 47 | ``` 48 | 49 | # Usage 50 | --- 51 | Once you have correctly added those lines to your build.gradle file, you can start using gettext: 52 | 53 | ``` java 54 | public class MainActivity extends AppCompatActivity { 55 | 56 | @Override 57 | protected void onCreate(Bundle savedInstanceState) { 58 | super.onCreate(savedInstanceState); 59 | setContentView(R.layout.activity_main); 60 | 61 | // Initialize PO with your context to get the device's locale. 62 | // You can also use a specific locale by using PO.setLocale(Context context, String locale). 63 | 64 | PO.setLocale(this); 65 | 66 | // Use simple translated string with PO.gettext(String msgId) 67 | 68 | ((TextView) findViewById(R.id.apples)).setText(PO.gettext("Choose number of apples")); 69 | ((TextView) findViewById(R.id.exclu)).setText(PO.gettext("Exclu fr")); 70 | 71 | ((SeekBar) findViewById(R.id.seek_bar)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 72 | @Override 73 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 74 | 75 | // Or use plurals with PO.ngettext(String msgId, String msgIdPlural, Integer number) 76 | ((TextView) findViewById(R.id.x_apples)).setText(PO.ngettext("%d apple", "%d apples", progress)); 77 | 78 | } 79 | 80 | @Override 81 | public void onStartTrackingTouch(SeekBar seekBar) {} 82 | 83 | @Override 84 | public void onStopTrackingTouch(SeekBar seekBar) {} 85 | }); 86 | } 87 | } 88 | 89 | ``` 90 | 91 | 92 | --- 93 | 94 | 95 | # About this library 96 | 97 | Localization on Android is convenient enough for your app as long as you don't need to use same translations for an iOS app. 98 | As you might know, iOS localization works with different files, different injections characters, and different keys system. 99 | 100 | At Mapstr, we have been undergoing with this issue and every new translation was a pain to add and use. We needed to translate, 101 | have it in the right format for both platforms, hence manage a double keys / value, and of course trying to avoid duplicated 102 | and missing strings. 103 | 104 | For this reason we thought about having a true multi-platform tool that would allow us to have a same translation base, in 105 | a way that iOS and Android could use it. Keeping goals in mind, our researches pinpointed the .po format, used by many 106 | softwares and supported by many translations services. Moreover, it manages plurals better than the regular .xml files, 107 | as plural rules are declared directly in the .po file. 108 | 109 | The challenge on Android was to have a simple enough system that would give the developer the opportunity to simply integrate 110 | his .po translation files dependencies. 111 | 112 | At Gradle Sync time, the plugin considers every module in the current project tree and seek for a `po/` folder at root. 113 | For each found module, the plugin will download and run a python script to generate java classes with those po files under 114 | the `build/generated/sources/translations/` folder, and add it as a source set to the project. One class is generated for 115 | each .po file under the source `po/` folder. 116 | 117 | Those classes will be processed by your build script, and stay available at runtime, Gettext library will be able to reach 118 | out the right translation class depending on the locale found in the initializing context. You can obviously initialize 119 | Gettext with a specific locale. 120 | 121 | 122 | 123 | # Next improvements 124 | 125 | This plugin and library are a usable proof of concept. It is convenient enough for your translation flow, but is far from 126 | xml usability in android development. You don't have any auto-completion, so it's easy to make a mistake when using Gettext. 127 | For this reason, one of the next improvements will be to create a Android Studio plugin to make those strings recognized by 128 | your development environment, and have auto-completion back in the game. 129 | 130 | Obviously, as this lib and plugin are open-source, I'm more than open to suggestions, and would be happy to make and see this 131 | cross-platform ambition becoming a reference for building localized apps. 132 | 133 | 134 | 135 | # Credits 136 | 137 | Many thanks to Aurélien Gâteau who wrote the scripts to generate java classes from PO files. -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | buildscript { 4 | repositories { 5 | mavenCentral() 6 | google() 7 | jcenter() 8 | maven { 9 | url "https://plugins.gradle.org/m2/" 10 | } 11 | } 12 | dependencies { 13 | classpath "gradle.plugin.com.hulab.gradle:gradle-plugin:1.0.0" 14 | } 15 | } 16 | 17 | android { 18 | compileSdkVersion 26 19 | defaultConfig { 20 | applicationId "com.hulab.gettext.example" 21 | minSdkVersion 15 22 | targetSdkVersion 26 23 | versionCode 1 24 | versionName "1.0.0" 25 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 26 | } 27 | buildTypes { 28 | release { 29 | minifyEnabled false 30 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 31 | } 32 | } 33 | } 34 | 35 | dependencies { 36 | implementation fileTree(include: ['*.jar'], dir: 'libs') 37 | implementation 'com.android.support:appcompat-v7:26.1.0' 38 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 39 | implementation 'com.android.support:support-annotations:27.1.0' 40 | //implementation 'com.hulab.android:gettext:1.0.0' 41 | implementation project(':gettext') 42 | testImplementation 'junit:junit:4.12' 43 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 44 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 45 | } 46 | 47 | apply plugin: "com.hulab.gradle.gettext-android" -------------------------------------------------------------------------------- /app/po/fr.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: Example\n" 4 | "Report-Msgid-Bugs-To: \n" 5 | "POT-Creation-Date: 2018-01-03 11:49+0100\n" 6 | "PO-Revision-Date: 2018-01-03 11:52+0100\n" 7 | "Last-Translator: Andrej Mihajlov \n" 8 | "Language-Team: \n" 9 | "Language: fr\n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | "X-Generator: Poedit 2.0.5\n" 14 | "X-Poedit-KeywordsList: _;_x:2c,1;_nx:4c,1,2;_n:1,2;_n_noop:1,2;" 15 | "PO.gettext:2;" 16 | "PO.ngettext:2,3\n" 17 | "Plural-Forms: nplurals=2; plural=(n > 1);\n" 18 | "X-Poedit-SourceCharset: UTF-8\n" 19 | "X-Poedit-Basepath: ../src/main/java\n" 20 | "X-Poedit-SearchPath-0: .\n" 21 | 22 | #: com/hulab/gettext/example/MainActivity.java:16 23 | msgid "Choose number of apples" 24 | msgstr "Choisissez un nombre de pommes" 25 | 26 | #: com/hulab/gettext/example/MainActivity.java:17 27 | msgid "Exclu fr" 28 | msgstr "Exclusivité du Français" 29 | 30 | #: com/hulab/gettext/example/MainActivity.java:21 31 | msgid "%i apple" 32 | msgid_plural "%i apples" 33 | msgstr[0] "%i pomme" 34 | msgstr[1] "%i pommes" 35 | -------------------------------------------------------------------------------- /app/po/fr_CH.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: Example\n" 4 | "Report-Msgid-Bugs-To: \n" 5 | "POT-Creation-Date: 2017-12-06 16:41+0100\n" 6 | "PO-Revision-Date: 2017-12-13 14:53+0100\n" 7 | "Last-Translator: Andrej Mihajlov \n" 8 | "Language-Team: \n" 9 | "Language: fr_CH\n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | "X-Generator: Poedit 2.0.5\n" 14 | "X-Poedit-KeywordsList: _;_x:2c,1;_nx:4c,1,2;_n:1,2;_n_noop:1,2;_nx_noop:3c,1,2;POLocalizedString;" 15 | "POLocalizedStringFromContext:2c,1;POLocalizedPluralFormat:3c,1,2;" 16 | "POLocalizedPluralFormatFromContext:4c,1,2;POLocalizedStringInBundle:2;" 17 | "POLocalizedStringFromContextInBundle:3c,2;POLocalizedPluralFormatInBundle:2,3;" 18 | "POLocalizedPluralFormatFromContextInBundle:5c,2,3;J.getString:2\n" 19 | "Plural-Forms: nplurals=2; plural=(n > 1);\n" 20 | "X-Poedit-SourceCharset: UTF-8\n" 21 | "X-Poedit-Basepath: ../..\n" 22 | "X-Poedit-SearchPath-0: res/Example-swift\n" 23 | "X-Poedit-SearchPath-1: res/Examples-objc\n" 24 | "X-Poedit-SearchPath-2: java/com/hulab/exampleapp\n" 25 | 26 | msgid "Choose number of apples" 27 | msgstr "Choisissez un nombre de pommes pour la Suisse" 28 | 29 | msgid "Exclu fr" 30 | msgstr "Exclusivité du Français, éventuellement en Suisse" 31 | 32 | msgid "%i apple" 33 | msgid_plural "%i apples" 34 | msgstr[0] "%i pomme Suisse" 35 | msgstr[1] "%i pommes Suisses" 36 | -------------------------------------------------------------------------------- /app/po/ru.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: Example\n" 4 | "Report-Msgid-Bugs-To: \n" 5 | "POT-Creation-Date: 2018-01-03 11:54+0100\n" 6 | "PO-Revision-Date: 2018-01-03 11:55+0100\n" 7 | "Last-Translator: Andrej Mihajlov \n" 8 | "Language-Team: \n" 9 | "Language: ru\n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | "X-Generator: Poedit 2.0.5\n" 14 | "X-Poedit-KeywordsList: PO.gettext:2;PO.ngettext:2,3\n" 15 | "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" 16 | "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" 17 | "X-Poedit-SourceCharset: UTF-8\n" 18 | "X-Poedit-Basepath: ../src/main/java\n" 19 | "X-Poedit-SearchPath-0: .\n" 20 | 21 | #: com/hulab/gettext/example/MainActivity.java:16 22 | msgid "Choose number of apples" 23 | msgstr "Выберите количество ябло" 24 | 25 | #: com/hulab/gettext/example/MainActivity.java:17 26 | msgid "Exclu fr" 27 | msgstr "" 28 | 29 | #: com/hulab/gettext/example/MainActivity.java:21 30 | msgid "%i apple" 31 | msgid_plural "%i apples" 32 | msgstr[0] "%i яблоко" 33 | msgstr[1] "%i яблока" 34 | msgstr[2] "%i яблок" 35 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/hulab/gettext/example/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.hulab.gettext.example; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.hulab.ngettext.example", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/hulab/gettext/example/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.hulab.gettext.example; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.widget.SeekBar; 6 | import android.widget.TextView; 7 | 8 | import com.hulab.gettext.PO; 9 | 10 | public class MainActivity extends AppCompatActivity { 11 | 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.activity_main); 16 | PO.setLocale(this); 17 | 18 | ((TextView) findViewById(R.id.apples)).setText(PO.gettext("Choose number of apples")); 19 | 20 | ((TextView) findViewById(R.id.exclu)).setText(PO.gettext("Exclu fr")); 21 | ((SeekBar) findViewById(R.id.seek_bar)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 22 | @Override 23 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 24 | ((TextView) findViewById(R.id.x_apples)).setText(PO.ngettext("%i apple", "%i apples", progress)); 25 | } 26 | 27 | @Override 28 | public void onStartTrackingTouch(SeekBar seekBar) { 29 | 30 | } 31 | 32 | @Override 33 | public void onStopTrackingTouch(SeekBar seekBar) { 34 | 35 | } 36 | }); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 20 | 21 | 27 | 28 | 34 | 35 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hulab/gettext-android/70b921dd57d1811a6d14f8556b672aae76d7181a/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hulab/gettext-android/70b921dd57d1811a6d14f8556b672aae76d7181a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hulab/gettext-android/70b921dd57d1811a6d14f8556b672aae76d7181a/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hulab/gettext-android/70b921dd57d1811a6d14f8556b672aae76d7181a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hulab/gettext-android/70b921dd57d1811a6d14f8556b672aae76d7181a/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hulab/gettext-android/70b921dd57d1811a6d14f8556b672aae76d7181a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hulab/gettext-android/70b921dd57d1811a6d14f8556b672aae76d7181a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hulab/gettext-android/70b921dd57d1811a6d14f8556b672aae76d7181a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hulab/gettext-android/70b921dd57d1811a6d14f8556b672aae76d7181a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hulab/gettext-android/70b921dd57d1811a6d14f8556b672aae76d7181a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Gettext Example 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/hulab/gettext/example/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.hulab.gettext.example; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | 3 | buildscript { 4 | repositories { 5 | mavenCentral() 6 | mavenLocal() 7 | jcenter() 8 | google() 9 | } 10 | 11 | dependencies { 12 | classpath 'com.android.tools.build:gradle:3.1.0' 13 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' 14 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' 15 | } 16 | } 17 | allprojects { 18 | repositories { 19 | jcenter() 20 | google() 21 | } 22 | } 23 | 24 | dependencies { 25 | implementation project(':gradle-plugin') 26 | } -------------------------------------------------------------------------------- /gettext/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /gettext/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | apply plugin: 'com.jfrog.bintray' 4 | apply plugin: 'maven-publish' 5 | 6 | buildscript { 7 | repositories { 8 | mavenCentral() 9 | jcenter() 10 | google() 11 | } 12 | 13 | dependencies { 14 | classpath 'com.android.tools.build:gradle:3.1.0' 15 | } 16 | } 17 | 18 | 19 | apply plugin: 'com.jfrog.bintray' 20 | 21 | ext { 22 | bintrayRepo = 'Gettext-Android' 23 | bintrayName = 'gettext' 24 | 25 | publishedGroupId = 'com.hulab.android' 26 | libraryName = 'Gettext' 27 | artifact = 'gettext' 28 | 29 | libraryDescription = 'Gettext for Android allows you to use common po files to an Android project' 30 | 31 | siteUrl = 'https://github.com/hulab/gettext-android' 32 | gitUrl = 'https://github.com/hulab/gettext-android.git' 33 | 34 | libraryVersion = "1.0.1" 35 | 36 | developerId = 'nebneb' 37 | developerName = 'Pierre-Emmanuel Altieri' 38 | developerEmail = 'pe.altieri@gmail.com' 39 | 40 | licenseName = 'The Apache Software License, Version 2.0' 41 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 42 | allLicenses = ["Apache-2.0"] 43 | 44 | configurations = ['archives'] 45 | } 46 | 47 | bintray { 48 | user = System.getenv('BINTRAY_USER') 49 | key = System.getenv('BINTRAY_KEY') 50 | pkg { 51 | repo = 'Gettext-Android' 52 | name = 'gettext' 53 | userOrg = 'nebneb' 54 | licenses = ['Apache-2.0'] 55 | vcsUrl = 'https://github.com/hulab/gettext-android' 56 | version { 57 | name = "$libraryVersion" 58 | desc = "Gettext for Android version $libraryVersion" 59 | released = new Date() 60 | vcsTag = "$libraryVersion" 61 | attributes = ['gradle-plugin': 'com.use.less:com.use.less.gradle:gradle-useless-plugin'] 62 | } 63 | } 64 | } 65 | 66 | install { 67 | repositories.mavenInstaller { 68 | pom.project { 69 | name "$libraryName" 70 | description "$libraryDescription" 71 | groupId "$publishedGroupId" 72 | artifactId "$artifact" 73 | version "$libraryVersion" 74 | url = "$siteUrl" 75 | packaging 'aar' 76 | 77 | licenses { 78 | license { 79 | name 'The Apache Software License, Version 2.0' 80 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 81 | distribution 'repo' 82 | } 83 | } 84 | scm { 85 | connection "$gitUrl" 86 | url "$siteUrl" 87 | 88 | } 89 | } 90 | } 91 | } 92 | 93 | android { 94 | compileSdkVersion 26 95 | 96 | defaultConfig { 97 | minSdkVersion 15 98 | targetSdkVersion 26 99 | versionCode 2 100 | versionName "$libraryVersion" 101 | 102 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 103 | } 104 | 105 | buildTypes { 106 | release { 107 | minifyEnabled false 108 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 109 | } 110 | } 111 | } 112 | 113 | dependencies { 114 | implementation fileTree(dir: 'libs', include: ['*.jar']) 115 | implementation 'com.android.support:appcompat-v7:26.1.0' 116 | testImplementation 'junit:junit:4.12' 117 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 118 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 119 | } 120 | 121 | 122 | tasks.withType(Javadoc) { 123 | options.addStringOption('Xdoclint:none', '-quiet') 124 | options.addStringOption('encoding', 'UTF-8') 125 | options.addStringOption('charSet', 'UTF-8') 126 | } 127 | 128 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle' 129 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle' -------------------------------------------------------------------------------- /gettext/gradle.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hulab/gettext-android/70b921dd57d1811a6d14f8556b672aae76d7181a/gettext/gradle.properties -------------------------------------------------------------------------------- /gettext/local.properties: -------------------------------------------------------------------------------- 1 | ## This file is automatically generated by Android Studio. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must *NOT* be checked into Version Control Systems, 5 | # as it contains information specific to your local configuration. 6 | # 7 | # Location of the SDK. This is only used by Gradle. 8 | # For customization when using a Version Control System, please read the 9 | # header note. 10 | #Thu Mar 22 16:15:14 CET 2018 11 | ndk.dir=/Users/nebneb/Library/Android/sdk/ndk-bundle 12 | sdk.dir=/Users/nebneb/Library/Android/sdk 13 | -------------------------------------------------------------------------------- /gettext/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /gettext/src/androidTest/java/com/hulab/gettext/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.hulab.gettext; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.hulab.PO.PO.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /gettext/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /gettext/src/main/java/com/hulab/gettext/CFormatter.java: -------------------------------------------------------------------------------- 1 | package com.hulab.gettext; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * Created by nebneb on 11/04/2018. 8 | */ 9 | 10 | public class CFormatter { 11 | 12 | private static final HashMap injections = new HashMap(){{put("%i", "%d");}}; 13 | 14 | static String format(String string) { 15 | if (string == null) return null; 16 | for (Map.Entry entry : injections.entrySet()) 17 | string = string.replaceAll(entry.getKey(), entry.getValue()); 18 | return string; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /gettext/src/main/java/com/hulab/gettext/Messages.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Aurélien Gâteau 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hulab.gettext; 17 | 18 | import android.content.Context; 19 | import android.util.Log; 20 | 21 | import java.util.HashMap; 22 | 23 | public class Messages { 24 | 25 | protected final HashMap entries = new HashMap(); 26 | protected final HashMap plurals = new HashMap(); 27 | 28 | static Messages load(Context context, String locale) throws ClassNotFoundException, IllegalAccessException, InstantiationException { 29 | String className = context.getPackageName() + "." + locale; 30 | Log.d("GETTEXT", "loading class " + className); 31 | Class clazz = Class.forName(className); 32 | return (Messages) clazz.newInstance(); 33 | } 34 | 35 | protected int plural(int n) { 36 | return n == 1 ? 0 : 1; 37 | } 38 | 39 | String gettext(String msgid) { 40 | String msgstr = entries.get(new Entry(msgid)); 41 | return msgstr == null ? msgid : msgstr; 42 | } 43 | 44 | String xgettext(String msgid, String context) { 45 | String msgstr = entries.get(new Entry(msgid, context)); 46 | return msgstr == null ? msgid : msgstr; 47 | } 48 | 49 | String ngettext(String msgid, String msgid_plural, int n) { 50 | return resolve(new Plural(msgid, msgid_plural), n); 51 | } 52 | 53 | String nxgettext(String msgid, String msgid_plural, String context, int n) { 54 | return resolve(new Plural(msgid, msgid_plural, context), n); 55 | } 56 | 57 | String resolve(Plural plural, int n) { 58 | String[] msgstr = plurals.get(plural); 59 | 60 | if (msgstr == null) { 61 | return n == 1 ? plural.msgid : plural.msgid_plural; 62 | } 63 | 64 | // Should check bounds 65 | return msgstr[plural(n)]; 66 | } 67 | 68 | protected static class Entry { 69 | 70 | protected final String msgid; 71 | protected final String context; 72 | 73 | public Entry(String msgid) { 74 | this.msgid = msgid; 75 | this.context = ""; 76 | } 77 | 78 | protected Entry(String msgid, String context) { 79 | this.msgid = msgid; 80 | this.context = context; 81 | } 82 | 83 | @Override 84 | public int hashCode() { 85 | return (context + '|' + msgid).hashCode(); 86 | } 87 | 88 | @Override 89 | public boolean equals(Object obj) { 90 | if (!(obj instanceof Entry)) { 91 | return false; 92 | } 93 | 94 | Entry other = (Entry) obj; 95 | return context.equals(other.context) && msgid.equals(other.msgid); 96 | } 97 | } 98 | 99 | protected static class Plural extends Entry { 100 | 101 | protected final String msgid_plural; 102 | 103 | protected Plural(String msgid, String msgid_plural, String context) { 104 | super(msgid, context); 105 | this.msgid_plural = msgid_plural; 106 | } 107 | 108 | public Plural(String msgid, String msgid_plural) { 109 | super(msgid); 110 | this.msgid_plural = msgid_plural; 111 | } 112 | 113 | @Override 114 | public int hashCode() { 115 | return (context + '|' + msgid + '|' + msgid_plural).hashCode(); 116 | } 117 | 118 | @Override 119 | public boolean equals(Object obj) { 120 | if (!(obj instanceof Plural)) { 121 | return false; 122 | } 123 | 124 | Plural other = (Plural) obj; 125 | return context.equals(other.context) && msgid.equals(other.msgid) && msgid_plural.equals(other.msgid_plural); 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /gettext/src/main/java/com/hulab/gettext/PO.java: -------------------------------------------------------------------------------- 1 | package com.hulab.gettext; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | 6 | import java.util.Locale; 7 | 8 | 9 | public class PO { 10 | 11 | private final static String TAG = "GETTEXT"; 12 | 13 | private static Messages sMessages = null; 14 | 15 | private static Messages sharedMessages(Context context) { 16 | 17 | if (sMessages == null) { 18 | String locale = Locale.getDefault().toString(); 19 | setLocale(context, locale); 20 | } 21 | 22 | return sMessages; 23 | } 24 | 25 | 26 | public static void setLocale(Context context) { 27 | String locale = Locale.getDefault().toString(); 28 | setLocale(context, locale); 29 | } 30 | 31 | /** 32 | * Set the current app's language manually. Otherwise, it will just take into account the 33 | * default locale. 34 | * 35 | * @param context The current context. This context must be non-null. 36 | * @param locale The ISO code of the language, for example "en", "ru", "fr", "fr_CH". 37 | */ 38 | public static void setLocale(Context context, String locale) { 39 | 40 | try { 41 | 42 | sMessages = Messages.load(context, locale); 43 | 44 | } catch (ClassNotFoundException e) { 45 | 46 | // try with the language iso code 47 | int idx = locale.indexOf('_'); 48 | if (idx > -1) { 49 | setLocale(context, locale.substring(0, idx)); 50 | } else { 51 | Log.w(TAG, "Locale not found ! Falling back on msg ids."); 52 | sMessages = new Messages(); 53 | } 54 | 55 | } catch (Exception e) { 56 | Log.e(TAG, "Something went wrong while trying to set locale."); 57 | sMessages = new Messages(); 58 | } 59 | } 60 | 61 | /** 62 | * Returns the translated string for the given key. The string is translated in the set language 63 | * if such a file is available. 64 | *

65 | * Fallbacks are the following if only "en", "fr", and "pt-BR" are available: 66 | *

67 | * "en_US" -> "en" 68 | * "fr_CH" -> "fr" 69 | * "pt_BR" -> "pt_BR" 70 | * "pt" -> {@param msgid} 71 | * 72 | * @param msgid the key of the message 73 | * @return The translated message for the given key. 74 | */ 75 | public static String gettext(String msgid) { 76 | assert sMessages != null : "should call setLocale(§)"; 77 | return sMessages.gettext(CFormatter.format(msgid)); 78 | } 79 | 80 | /** 81 | * Returns the translated string for the given key. The string is translated in the set language 82 | * if such a file is available. 83 | *

84 | * Fallbacks are the following if only "en", "fr", and "pt-BR" are available: 85 | *

86 | * "en_US" -> "en" 87 | * "fr_CH" -> "fr" 88 | * "pt_BR" -> "pt_BR" 89 | * "pt" -> {@param msgid} 90 | * 91 | * @param msgid the key of the message 92 | * @param args For string injections 93 | * @return The translated message for the given key. 94 | */ 95 | public static String gettext(String msgid, Object... args) { 96 | assert sMessages != null : "should call setLocale(§)"; 97 | return String.format(CFormatter.format(sMessages.gettext(msgid)), args); 98 | } 99 | 100 | /** 101 | * Returns the translated string for the given key. The string is translated in the set language 102 | * if such a file is available. 103 | *

104 | * Fallbacks are operating in the same way than {@link #gettext(String)}. 105 | * Plurals rules are referring to the ones given in the .po files. If no locale is available, 106 | * The last fallback is "en" rules: if {@param n} == 1, we use {@param msgid} as fallback. If 107 | * different than 1, we use {@param msgid_plural} as fallback. 108 | * 109 | * @param msgid the key of the message 110 | * @param msgid_plural the plural key of the message 111 | * @param n the quantity to consider when getting the plural form 112 | * @return The translated message for the given key in the given quantity. 113 | * Quantity is injected in the resulting string using 114 | * {@link java.lang.String#format(String, Object...) String.format()} method. 115 | */ 116 | public static String ngettext(String msgid, String msgid_plural, int n) { 117 | assert sMessages != null : "should call setLocale(§)"; 118 | return String.format(CFormatter.format(sMessages.ngettext(msgid, msgid_plural, n)), n); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /gettext/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | gettext 3 | 4 | -------------------------------------------------------------------------------- /gettext/src/test/java/com/hulab/gettext/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.hulab.gettext; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /gradle-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Android template 3 | # Built application files 4 | *.apk 5 | *.ap_ 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | 18 | # Gradle files 19 | .gradle/ 20 | build/ 21 | 22 | # Local configuration file (sdk path, etc) 23 | local.properties 24 | 25 | # Proguard folder generated by Eclipse 26 | proguard/ 27 | 28 | # Log Files 29 | *.log 30 | 31 | # Android Studio Navigation editor temp files 32 | .navigation/ 33 | 34 | # Android Studio captures folder 35 | captures/ 36 | 37 | # IntelliJ 38 | *.iml 39 | .idea/workspace.xml 40 | .idea/tasks.xml 41 | .idea/gradle.xml 42 | .idea/dictionaries 43 | .idea/libraries 44 | 45 | # Keystore files 46 | # Uncomment the following line if you do not want to check your keystore files in. 47 | #*.jks 48 | 49 | # External native build folder generated in Android Studio 2.2 and later 50 | .externalNativeBuild 51 | 52 | # Google Services (e.g. APIs or Firebase) 53 | google-services.json 54 | 55 | # Freeline 56 | freeline.py 57 | freeline/ 58 | freeline_project_description.json 59 | ### Gradle template 60 | .gradle 61 | /build/ 62 | 63 | # Ignore Gradle GUI config 64 | gradle-app.setting 65 | 66 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 67 | !gradle-wrapper.jar 68 | 69 | # Cache of project 70 | .gradletasknamecache 71 | 72 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 73 | # gradle/wrapper/gradle-wrapper.properties 74 | 75 | /.gradle/ 76 | -------------------------------------------------------------------------------- /gradle-plugin/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | mavenLocal() 5 | jcenter() 6 | maven { url "https://plugins.gradle.org/m2/" } 7 | } 8 | 9 | dependencies { 10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' 11 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' 12 | classpath "com.gradle.publish:plugin-publish-plugin:0.9.10" 13 | } 14 | } 15 | 16 | apply plugin: 'groovy' 17 | apply plugin: 'maven' 18 | apply plugin: 'maven-publish' 19 | apply plugin: "com.gradle.plugin-publish" 20 | 21 | def pluginVersion = "1.0.0" 22 | 23 | sourceCompatibility = 1.7 24 | 25 | group 'com.hulab.gradle' 26 | version "$pluginVersion" 27 | 28 | 29 | pluginBundle { 30 | website = 'https://github.com/hulab/gettext-android' 31 | vcsUrl = 'https://github.com/hulab/gettext-android' 32 | description = 'Gradle plugin to compile po files.' 33 | tags = ['android', 'build', 'gettext', 'translation', 'localization'] 34 | 35 | plugins { 36 | greetingsPlugin { 37 | id = 'com.hulab.gradle.gettext-android' 38 | displayName = 'gettext-android Gradle plugin' 39 | } 40 | } 41 | } 42 | 43 | repositories { 44 | mavenCentral() 45 | mavenLocal() 46 | jcenter() 47 | } 48 | 49 | dependencies { 50 | compile 'org.codehaus.groovy:groovy-all:2.4.12' 51 | compile gradleApi() 52 | compile localGroovy() 53 | } -------------------------------------------------------------------------------- /gradle-plugin/gradle.properties: -------------------------------------------------------------------------------- 1 | 2 | POM_NAME=Gettext for Android Gradle Plugin 3 | POM_ARTIFACT_ID=gettext-android 4 | POM_PACKAGING=jar -------------------------------------------------------------------------------- /gradle-plugin/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'gettext-android' 2 | 3 | -------------------------------------------------------------------------------- /gradle-plugin/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /gradle-plugin/src/main/groovy/com/hulab/gradle/GettextAndroid.groovy: -------------------------------------------------------------------------------- 1 | package com.hulab.gradle 2 | 3 | import org.gradle.api.Plugin 4 | import org.gradle.api.Project 5 | 6 | import java.nio.file.Files 7 | import java.nio.file.attribute.PosixFilePermission 8 | 9 | class GettextAndroid implements Plugin { 10 | @Override 11 | void apply(Project target) { 12 | def pofolder = new File("${target.projectDir}/po/") 13 | if (pofolder.exists()) { 14 | target.task("executePoCompile") { 15 | executePoCompile(target) 16 | } 17 | } 18 | } 19 | 20 | void executePoCompile(Project project) { 21 | println("Executing PO compile...") 22 | def packageName = "${project.android.defaultConfig.applicationId}" 23 | if (project.hasProperty('poPackageName')) 24 | packageName = "${project.poPackageName}" 25 | 26 | def endDir = packageName.replace('.', '/') 27 | def outputDir = new File("${project.buildDir}/generated/source/translations/${endDir}") 28 | 29 | outputDir.exists() || outputDir.mkdirs() 30 | 31 | project.android.sourceSets.main.java.srcDirs { 32 | 'build/generated/source/translations' 33 | } 34 | 35 | downloadScripts(project) 36 | 37 | 38 | def cmd = ["${project.buildDir}/scripts/po-compile-all", "${project.projectDir}/po", "${outputDir.path}", packageName] 39 | println(cmd) 40 | 41 | def sout = new StringBuilder(), serr = new StringBuilder() 42 | def proc = cmd.execute() 43 | 44 | proc.consumeProcessOutput(sout, serr) 45 | proc.waitForOrKill(3000) 46 | 47 | println "out> $sout err> $serr" 48 | 49 | println("PO compile done.") 50 | } 51 | 52 | void downloadScripts(Project project) { 53 | def address = "https://git.hulab.co/hulab/gettext-android/raw/master/gradle-plugin/src/scripts.zip" 54 | def dest = "$project.buildDir/scripts.zip" 55 | 56 | new File(dest).withOutputStream { out -> 57 | new URL(address).withInputStream { from -> out << from 58 | } 59 | } 60 | extract(dest, project) 61 | } 62 | 63 | void extract(String zipPath, Project project) { 64 | def dest = "${project.buildDir}/" 65 | new AntBuilder().unzip( 66 | src: zipPath, 67 | dest: dest, 68 | overwrite: "true") 69 | 70 | Set perms = new HashSet<>() 71 | perms.add(PosixFilePermission.OWNER_READ) 72 | perms.add(PosixFilePermission.OWNER_WRITE) 73 | perms.add(PosixFilePermission.OWNER_EXECUTE) 74 | 75 | File poCompileAll = new File("${dest}scripts/po-compile-all") 76 | File poCompilePy = new File("${dest}scripts/po-compile.py") 77 | Files.setPosixFilePermissions(poCompileAll.toPath(), perms) 78 | Files.setPosixFilePermissions(poCompilePy.toPath(), perms) 79 | } 80 | } -------------------------------------------------------------------------------- /gradle-plugin/src/main/resources/META-INF/gradle-plugins/com.hulab.gradle.gettext-android.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.hulab.gradle.GettextAndroid -------------------------------------------------------------------------------- /gradle-plugin/src/scripts.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hulab/gettext-android/70b921dd57d1811a6d14f8556b672aae76d7181a/gradle-plugin/src/scripts.zip -------------------------------------------------------------------------------- /gradle-plugin/src/scripts/Messages.java.tmpl: -------------------------------------------------------------------------------- 1 | // This file has been dynamically generated by {{generator}}. 2 | // Do not modify it, all changes will be lost. 3 | 4 | package {{ package }}; 5 | 6 | public class {{ locale }} extends com.hulab.gettext.Messages { 7 | 8 | public {{ locale }}() { 9 | {%- for msgid, msgstr in plain_entries %} 10 | entries.put(new Entry("{{ msgid }}"), "{{ msgstr }}"); 11 | {%- endfor %} 12 | 13 | 14 | {%- for msgid, msgstr, msgctxt in ctxt_entries %} 15 | entries.put(new Entry("{{ msgid }}", "{{ msgctxt }}"), "{{ msgstr }}"); 16 | {%- endfor %} 17 | 18 | {%- for msgid, msgid_plural, lst in plain_plurals %} 19 | plurals.put( 20 | new Plural("{{ msgid }}", "{{ msgid_plural }}"), 21 | new String[] { 22 | {%- for msgstr in lst %} 23 | "{{ msgstr }}", 24 | {%- endfor %} 25 | } 26 | ); 27 | {%- endfor %} 28 | 29 | {%- for msgid, msgid_plural, lst, msgctxt in plurals %} 30 | plurals.put( 31 | new Plural("{{ msgid }}", "{{ msgctxt }}", "{{ msgid_plural }}"), 32 | new String[] { 33 | {%- for msgstr in lst %} 34 | "{{ msgstr }}", 35 | {%- endfor %} 36 | } 37 | ); 38 | {%- endfor %} 39 | } 40 | 41 | @Override 42 | protected int plural(int n) { 43 | return {{ plural_code }} 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /gradle-plugin/src/scripts/po-compile-all: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | # Copyright 2014 Aurélien Gâteau 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | old_pwd=$PWD 19 | cd $(dirname $0) 20 | script_dir=$PWD 21 | cd $old_pwd 22 | 23 | die() { 24 | echo "ERROR: $*" >&2 25 | exit 1 26 | } 27 | 28 | usage() { 29 | echo "$(basename $0) " 30 | exit 1 31 | } 32 | 33 | if [ $# < 2 ] ; then 34 | usage 35 | fi 36 | 37 | src="$1" 38 | dst="$2" 39 | pkg="$3" 40 | 41 | if [ ! -d "$src" ] ; then 42 | die "'$src' is not a dir" 43 | fi 44 | 45 | if [ ! -d "$dst" ] ; then 46 | die "'$dst' is not a dir" 47 | fi 48 | 49 | if [ ! "$pkg" ] ; then 50 | die "'$pkg' invalid package" 51 | fi 52 | 53 | for po in $src/*.po ; do 54 | echo "Compiling $po" 55 | locale=$(basename $po .po) 56 | $script_dir/po-compile.py -p $pkg -o $dst/$locale.java -l $locale $po 57 | done 58 | -------------------------------------------------------------------------------- /gradle-plugin/src/scripts/po-compile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # encoding: utf-8 3 | 4 | """ 5 | Copyright 2014 Aurélien Gâteau 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | """ 19 | 20 | # Python 2/3 compatibility 21 | from __future__ import division, absolute_import, print_function, unicode_literals 22 | 23 | import argparse 24 | import os 25 | import sys 26 | 27 | import jinja2 28 | import polib 29 | 30 | DESCRIPTION = """\ 31 | Generates .java files from .po files. 32 | 33 | The generated .java files can then be used with the Translator class. 34 | """ 35 | 36 | ESCAPES = [("'" , r"\'"), ('\n',r'\n'), ('"', r'\"')] 37 | def escape(txt): 38 | for src, dst in ESCAPES: 39 | txt = txt.replace(src, dst) 40 | return txt 41 | 42 | 43 | def escape_plural(dct): 44 | return [escape(dct[x]) for x in sorted(dct.keys())] 45 | 46 | 47 | def extract_plural_code(txt): 48 | is_boolean = txt.startswith("nplurals=2") 49 | code = txt.split("plural=")[1] 50 | if is_boolean: 51 | return code.strip(";") + " ? 1 : 0;" 52 | else: 53 | return code 54 | 55 | 56 | def process(package, locale, pofile, out): 57 | generator = os.path.basename(sys.argv[0]) 58 | 59 | tmpl_path = os.path.join(os.path.dirname(__file__), "Messages.java.tmpl") 60 | with open(tmpl_path) as f: 61 | tmpl = jinja2.Template(f.read()) 62 | 63 | entries = pofile.translated_entries() 64 | plain_entries = [(escape(x.msgid), escape(x.msgstr)) for x in entries if not x.msgstr_plural and not x.msgctxt] 65 | ctxt_entries = [(escape(x.msgid), escape(x.msgstr), escape(x.msgctxt)) for x in entries if x.msgctxt and not x.msgstr_plural] 66 | plain_plurals = [(escape(x.msgid), escape(x.msgid_plural), escape_plural(x.msgstr_plural)) for x in entries if x.msgstr_plural and not x.msgctxt] 67 | ctxt_plurals = [(escape(x.msgid), escape(x.msgid_plural), escape_plural(x.msgstr_plural), escape(x.msgctxt)) for x in entries if x.msgstr_plural and x.msgctxt] 68 | plural_code = extract_plural_code(pofile.metadata["Plural-Forms"]) 69 | 70 | txt = tmpl.render(dict( 71 | package=package, 72 | locale=locale, 73 | plain_entries=plain_entries, 74 | ctxt_entries=ctxt_entries, 75 | plain_plurals=plain_plurals, 76 | ctxt_plurals=ctxt_plurals, 77 | plural_code=plural_code, 78 | generator=generator, 79 | )) 80 | out.write(txt.encode("utf-8")) 81 | 82 | 83 | def parse_args(): 84 | parser = argparse.ArgumentParser(description=DESCRIPTION) 85 | 86 | parser.add_argument("-o", "--output", default="-", 87 | help="write code to FILE. Defaults to stdout.", metavar="FILE") 88 | 89 | parser.add_argument("-l", "--locale", required=True, 90 | help="name of the locale (for example \"fr\" or \"pt_BR\"") 91 | 92 | parser.add_argument("-p", "--package", required=True, 93 | help="name of the java package (for example \"com.hulab.gettext.po\"") 94 | 95 | parser.add_argument("po_file", 96 | help="file to parse") 97 | 98 | return parser.parse_args() 99 | 100 | 101 | def main(): 102 | args = parse_args() 103 | if args.output == "-": 104 | out = sys.stdout 105 | else: 106 | out = open(args.output, "w") 107 | 108 | if not os.path.exists(args.po_file): 109 | print("{} does not exist".format(args.po_file), file=sys.stderr) 110 | return 1 111 | pofile = polib.pofile(args.po_file) 112 | process(args.package, args.locale, pofile, out) 113 | 114 | return 0 115 | 116 | 117 | if __name__ == "__main__": 118 | sys.exit(main()) 119 | # vi: ts=4 sw=4 et 120 | -------------------------------------------------------------------------------- /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 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | android.enableBuildScriptClasspathCheck=false -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hulab/gettext-android/70b921dd57d1811a6d14f8556b672aae76d7181a/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Mar 27 12:32:02 CEST 2018 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-4.4-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 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | false 11 | 12 | bintray-nebneb-Gettext-Android 13 | bintray 14 | https://dl.bintray.com/nebneb/Gettext-Android 15 | 16 | 17 | 18 | 19 | 20 | false 21 | 22 | bintray-nebneb-Gettext-Android 23 | bintray-plugins 24 | https://dl.bintray.com/nebneb/Gettext-Android 25 | 26 | 27 | bintray 28 | 29 | 30 | 31 | bintray 32 | 33 | 34 | 35 | bintray-nebneb-Gettext-Android 36 | nebneb-Gettext-Android 37 | https://api.bintray.com/maven/nebneb/Gettext-Android/gettext/;publish=1 38 | 39 | 40 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':gradle-plugin', ':app', ':gettext' --------------------------------------------------------------------------------