├── settings.gradle ├── .gitignore ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── sample ├── build.gradle └── src │ └── main │ ├── res │ ├── values-ru │ │ └── strings.xml │ ├── values │ │ └── strings.xml │ └── layout │ │ └── main.xml │ ├── AndroidManifest.xml │ └── java │ └── com │ └── seppius │ └── plurals │ └── test │ └── TestPluralsActivity.java ├── library ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── seppius │ │ └── i18n │ │ └── plurals │ │ ├── PluralRules_Macedonian.java │ │ ├── PluralRules_French.java │ │ ├── PluralRules_Czech.java │ │ ├── PluralRules_Langi.java │ │ ├── PluralRules_Latvian.java │ │ ├── PluralRules_Tachelhit.java │ │ ├── PluralRules_Romanian.java │ │ ├── PluralRules_Two.java │ │ ├── PluralRules_Slovenian.java │ │ ├── PluralRules_Polish.java │ │ ├── PluralRules_Zero.java │ │ ├── PluralRules_Maltese.java │ │ ├── PluralRules_Lithuanian.java │ │ ├── PluralRules_Welsh.java │ │ ├── PluralRules_Arabic.java │ │ ├── PluralRules_Breton.java │ │ ├── PluralRules_None.java │ │ ├── PluralRules_Balkan.java │ │ ├── PluralRules_One.java │ │ ├── PluralResources.java │ │ └── PluralRules.java └── build.gradle ├── LICENSE ├── gradlew.bat ├── README.md └── gradlew /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':library' 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /.idea 3 | gradle.properties 4 | local.properties 5 | .DS_Store 6 | /*/build 7 | *.iml -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/populov/android-i18n-plurals/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # suppress inspection "UnusedProperty" for whole file 2 | #Fri Sep 12 04:20:05 YEKT 2014 3 | distributionBase=GRADLE_USER_HOME 4 | distributionPath=wrapper/dists 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-bin.zip 8 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | } 5 | dependencies { 6 | classpath 'com.android.tools.build:gradle:0.12.2' 7 | } 8 | } 9 | apply plugin: 'com.android.application' 10 | 11 | dependencies { 12 | compile project(':library') 13 | } 14 | 15 | android { 16 | compileSdkVersion 19 17 | buildToolsVersion '19.1.0' 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /sample/src/main/res/values-ru/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | попугай 5 | Выберите язык 6 | До 7 | После 8 | 9 | 10 | %d попугай 11 | %d попугая 12 | %d попугаев 13 | %d попугаев 14 | 15 | 16 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | parrots 5 | Select language 6 | Before 7 | After 8 | 9 | 10 | No parrots 11 | %d parrot (one) 12 | %d parrots (two) 13 | %d parrots (few) 14 | %d parrots (many) 15 | %d parrots (other) 16 | 17 | 18 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Haunted Soft 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules_Macedonian.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | /** 3 | * Plural rules for Macedonian language 4 | * 5 | * Locales: mk 6 | * 7 | * Languages: 8 | * - Macedonian (mk) 9 | * 10 | * Rules: 11 | * one → n mod 10 is 1 and n is not 11; 12 | * other → everything else 13 | * 14 | * Reference CLDR Version 1.9 beta (2010-11-16 21:48:45 GMT) 15 | * @see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 16 | * @see http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 17 | * @see plurals.xml (local copy) 18 | * 19 | * @package I18n_Plural 20 | * @category Plural Rules 21 | * @author Korney Czukowski 22 | * @copyright (c) 2011 Korney Czukowski 23 | * @license MIT License 24 | */ 25 | 26 | /** 27 | * Converted to Java by Sam Marshak, 2012 28 | */ 29 | public class PluralRules_Macedonian extends PluralRules 30 | { 31 | public int quantityForNumber(int count) 32 | { 33 | if (count % 10 == 1 && count != 11) 34 | { 35 | return QUANTITY_ONE; 36 | } 37 | else 38 | { 39 | return QUANTITY_OTHER; 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules_French.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | /** 3 | * Plural rules for the following locales and languages 4 | * 5 | * Locales: ff fr kab 6 | * 7 | * Languages: 8 | * Fulah (ff) 9 | * French (fr) 10 | * Kabyle (kab) 11 | * 12 | * Rules: 13 | * one → n within 0..2 and n is not 2; 14 | * other → everything else 15 | * 16 | * Reference CLDR Version 1.9 beta (2010-11-16 21:48:45 GMT) 17 | * @see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 18 | * @see http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 19 | * @see plurals.xml (local copy) 20 | * 21 | * @package I18n_Plural 22 | * @category Plural Rules 23 | * @author Korney Czukowski 24 | * @copyright (c) 2011 Korney Czukowski 25 | * @license MIT License 26 | */ 27 | 28 | /** 29 | * Converted to Java by Sam Marshak, 2012 30 | */ 31 | public class PluralRules_French extends PluralRules 32 | { 33 | public int quantityForNumber(int count) 34 | { 35 | if (count >= 0 && count < 2) 36 | { 37 | return QUANTITY_ONE; 38 | } 39 | else 40 | { 41 | return QUANTITY_OTHER; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules_Czech.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | /** 3 | * Plural rules for the following locales and languages 4 | * 5 | * Locales: cs sk 6 | * 7 | * Languages: 8 | * - Czech (cs) 9 | * - Slovak (sk) 10 | * 11 | * Rules: 12 | * one → n is 1; 13 | * few → n in 2..4; 14 | * other → everything else 15 | * 16 | * Reference CLDR Version 1.9 beta (2010-11-16 21:48:45 GMT) 17 | * @see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 18 | * @see http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 19 | * @see plurals.xml (local copy) 20 | * 21 | * @package I18n_Plural 22 | * @category Plural Rules 23 | * @author Korney Czukowski 24 | * @copyright (c) 2011 Korney Czukowski 25 | * @license MIT License 26 | */ 27 | 28 | /** 29 | * Converted to Java by Sam Marshak, 2012 30 | */ 31 | public class PluralRules_Czech extends PluralRules 32 | { 33 | public int quantityForNumber(int count) 34 | { 35 | if (count == 1) 36 | { 37 | return QUANTITY_ONE; 38 | } 39 | else if (count >= 2 && count <= 4) 40 | { 41 | return QUANTITY_FEW; 42 | } 43 | else 44 | { 45 | return QUANTITY_OTHER; 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules_Langi.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | /** 3 | * Plural rules for Langi language: 4 | * 5 | * Locales: lag 6 | * 7 | * Languages: 8 | * - Langi (lag) 9 | * 10 | * Rules: 11 | * zero → n is 0; 12 | * one → n within 0..2 and n is not 0 and n is not 2; 13 | * other → everything else 14 | * 15 | * Reference CLDR Version 1.9 beta (2010-11-16 21:48:45 GMT) 16 | * @see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 17 | * @see http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 18 | * @see plurals.xml (local copy) 19 | * 20 | * @package I18n_Plural 21 | * @category Plural Rules 22 | * @author Korney Czukowski 23 | * @copyright (c) 2011 Korney Czukowski 24 | * @license MIT License 25 | */ 26 | 27 | /** 28 | * Converted to Java by Sam Marshak, 2012 29 | */ 30 | public class PluralRules_Langi extends PluralRules 31 | { 32 | public int quantityForNumber(int count) 33 | { 34 | if (count == 0) 35 | { 36 | return QUANTITY_ZERO; 37 | } 38 | else if (count > 0 && count < 2) 39 | { 40 | return QUANTITY_ONE; 41 | } 42 | else 43 | { 44 | return QUANTITY_OTHER; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules_Latvian.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | /** 3 | * Plural rules for Latvian language: 4 | * 5 | * Locales: lv 6 | * 7 | * Languages: 8 | * - Latvian (lv) 9 | * 10 | * Rules: 11 | * zero → n is 0; 12 | * one → n mod 10 is 1 and n mod 100 is not 11; 13 | * other → everything else 14 | * 15 | * Reference CLDR Version 1.9 beta (2010-11-16 21:48:45 GMT) 16 | * @see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 17 | * @see http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 18 | * @see plurals.xml (local copy) 19 | * 20 | * @package I18n_Plural 21 | * @category Plural Rules 22 | * @author Korney Czukowski 23 | * @copyright (c) 2011 Korney Czukowski 24 | * @license MIT License 25 | */ 26 | 27 | /** 28 | * Converted to Java by Sam Marshak, 2012 29 | */ 30 | public class PluralRules_Latvian extends PluralRules 31 | { 32 | public int quantityForNumber(int count) 33 | { 34 | if (count == 0) 35 | { 36 | return QUANTITY_ZERO; 37 | } 38 | else if (count % 10 == 1 && count % 100 != 11) 39 | { 40 | return QUANTITY_ONE; 41 | } 42 | else 43 | { 44 | return QUANTITY_OTHER; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules_Tachelhit.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | /** 3 | * Plural rules for Tachelhit language: 4 | * 5 | * Locales: shi 6 | * 7 | * Languages: 8 | * - Tachelhit (shi) 9 | * 10 | * Rules: 11 | * one → n within 0..1; 12 | * few → n in 2..10; 13 | * other → everything else 14 | * 15 | * Reference CLDR Version 1.9 beta (2010-11-16 21:48:45 GMT) 16 | * @see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 17 | * @see http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 18 | * @see plurals.xml (local copy) 19 | * 20 | * @package I18n_Plural 21 | * @category Plural Rules 22 | * @author Korney Czukowski 23 | * @copyright (c) 2011 Korney Czukowski 24 | * @license MIT License 25 | */ 26 | 27 | /** 28 | * Converted to Java by Sam Marshak, 2012 29 | */ 30 | public class PluralRules_Tachelhit extends PluralRules 31 | { 32 | public int quantityForNumber(int count) 33 | { 34 | if (count >= 0 && count <= 1) 35 | { 36 | return QUANTITY_ONE; 37 | } 38 | else if (count >= 2 && count <= 10) 39 | { 40 | return QUANTITY_FEW; 41 | } 42 | else 43 | { 44 | return QUANTITY_OTHER; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules_Romanian.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | /** 3 | * Plural rules for the following locales and languages: 4 | * 5 | * Locales: ro mo 6 | * 7 | * Languages: 8 | * Moldavian (mo) 9 | * Romanian (ro) 10 | * 11 | * Rules: 12 | * one → n is 1; 13 | * few → n is 0 || n is not 1 && n mod 100 in 1..19; 14 | * other → everything else 15 | * 16 | * Reference CLDR Version 1.9 beta (2010-11-16 21:48:45 GMT) 17 | * @see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 18 | * @see http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 19 | * @see plurals.xml (local copy) 20 | * 21 | * @package I18n_Plural 22 | * @category Plural Rules 23 | * @author Korney Czukowski 24 | * @copyright (c) 2011 Korney Czukowski 25 | * @license MIT License 26 | */ 27 | 28 | /** 29 | * Converted to Java by Sam Marshak, 2012 30 | */ 31 | public class PluralRules_Romanian extends PluralRules 32 | { 33 | public int quantityForNumber(int count) 34 | { 35 | int rem100 = count % 100; 36 | 37 | if (count == 1) 38 | { 39 | return QUANTITY_ONE; 40 | } 41 | else if ((count == 0 || (rem100 >= 1 && rem100 <= 19))) 42 | { 43 | return QUANTITY_FEW; 44 | } 45 | else 46 | { 47 | return QUANTITY_OTHER; 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules_Two.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | /** 3 | * Plural rules for the following locales and languages: 4 | * 5 | * Locales: ga se sma smi smj smn sms 6 | * 7 | * Languages: 8 | * Irish (ga) 9 | * Northern Sami (se) 10 | * Southern Sami (sma) 11 | * Sami Language (smi) 12 | * Lule Sami (smj) 13 | * Inari Sami (smn) 14 | * Skolt Sami (sms) 15 | * 16 | * Rules: 17 | * one → n is 1; 18 | * two → n is 2; 19 | * other → everything else 20 | * 21 | * Reference CLDR Version 1.9 beta (2010-11-16 21:48:45 GMT) 22 | * @see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 23 | * @see http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 24 | * @see plurals.xml (local copy) 25 | * 26 | * @package I18n_Plural 27 | * @category Plural Rules 28 | * @author Korney Czukowski 29 | * @copyright (c) 2011 Korney Czukowski 30 | * @license MIT License 31 | */ 32 | 33 | /** 34 | * Converted to Java by Sam Marshak, 2012 35 | */ 36 | public class PluralRules_Two extends PluralRules 37 | { 38 | public int quantityForNumber(int count) 39 | { 40 | if (count == 1) 41 | { 42 | return QUANTITY_ONE; 43 | } 44 | else if (count == 2) 45 | { 46 | return QUANTITY_TWO; 47 | } 48 | else 49 | { 50 | return QUANTITY_OTHER; 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules_Slovenian.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | /** 3 | * Plural rules for Slovenian language: 4 | * 5 | * Locales: sl 6 | * 7 | * Languages: 8 | * - Slovenian (sl) 9 | * 10 | * Rules: 11 | * one → n mod 100 is 1; 12 | * two → n mod 100 is 2; 13 | * few → n mod 100 in 3..4; 14 | * other → everything else 15 | * 16 | * Reference CLDR Version 1.9 beta (2010-11-16 21:48:45 GMT) 17 | * @see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 18 | * @see http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 19 | * @see plurals.xml (local copy) 20 | * 21 | * @package I18n_Plural 22 | * @category Plural Rules 23 | * @author Korney Czukowski 24 | * @copyright (c) 2011 Korney Czukowski 25 | * @license MIT License 26 | */ 27 | 28 | /** 29 | * Converted to Java by Sam Marshak, 2012 30 | */ 31 | public class PluralRules_Slovenian extends PluralRules 32 | { 33 | public int quantityForNumber(int count) 34 | { 35 | int rem100 = count % 100; 36 | 37 | if (rem100 == 1) 38 | { 39 | return QUANTITY_ONE; 40 | } 41 | else if (rem100 == 2) 42 | { 43 | return QUANTITY_TWO; 44 | } 45 | else if (rem100 >= 3 && rem100 <= 4) 46 | { 47 | return QUANTITY_FEW; 48 | } 49 | else 50 | { 51 | return QUANTITY_OTHER; 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules_Polish.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | /** 3 | * Plural rules for Polish language: 4 | * 5 | * Locales: pl 6 | * 7 | * Languages: 8 | * - Polish (pl) 9 | * 10 | * Rules: 11 | * one → n is 1; 12 | * few → n mod 10 in 2..4 and n mod 100 not in 12..14 and n mod 100 not in 22..24; 13 | * other → everything else (fractions) 14 | * 15 | * Reference CLDR Version 1.9 beta (2010-11-16 21:48:45 GMT) 16 | * @see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 17 | * @see http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 18 | * @see plurals.xml (local copy) 19 | * 20 | * @package I18n_Plural 21 | * @category Plural Rules 22 | * @author Korney Czukowski 23 | * @copyright (c) 2011 Korney Czukowski 24 | * @license MIT License 25 | */ 26 | 27 | /** 28 | * Converted to Java by Sam Marshak, 2012 29 | */ 30 | public class PluralRules_Polish extends PluralRules 31 | { 32 | public int quantityForNumber(int count) 33 | { 34 | int rem100 = count % 100; 35 | int rem10 = count % 10; 36 | 37 | if (count == 1) 38 | { 39 | return QUANTITY_ONE; 40 | } 41 | else if (rem10 >= 2 && rem10 <= 4 && !(rem100 >= 12 && rem100 <= 14)) 42 | { 43 | return QUANTITY_FEW; 44 | } 45 | else 46 | { 47 | return QUANTITY_OTHER; 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules_Zero.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | /** 3 | * Plural rules for the following locales and languages: 4 | * 5 | * Locales: ak am bh fil tl guw hi ln mg nso ti wa 6 | * 7 | * Languages: 8 | * Akan (ak) 9 | * Amharic (am) 10 | * Bihari (bh) 11 | * Filipino (fil) 12 | * Gun (guw) 13 | * Hindi (hi) 14 | * Lingala (ln) 15 | * Malagasy (mg) 16 | * Northern Sotho (nso) 17 | * Tigrinya (ti) 18 | * Tagalog (tl) 19 | * Walloon (wa) 20 | * 21 | * Rules: 22 | * one → n in 0..1; 23 | * other → everything else 24 | * 25 | * Reference CLDR Version 1.9 beta (2010-11-16 21:48:45 GMT) 26 | * @see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 27 | * @see http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 28 | * @see plurals.xml (local copy) 29 | * 30 | * @package I18n_Plural 31 | * @category Plural Rules 32 | * @author Korney Czukowski 33 | * @copyright (c) 2011 Korney Czukowski 34 | * @license MIT License 35 | */ 36 | 37 | /** 38 | * Converted to Java by Sam Marshak, 2012 39 | */ 40 | public class PluralRules_Zero extends PluralRules 41 | { 42 | public int quantityForNumber(int count) 43 | { 44 | if (count == 0 || count == 1) 45 | { 46 | return QUANTITY_ONE; 47 | } 48 | else 49 | { 50 | return QUANTITY_OTHER; 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules_Maltese.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | /** 3 | * Plural rules for Maltese language: 4 | * 5 | * Locales: mt 6 | * 7 | * Languages: 8 | * - Maltese (mt) 9 | * 10 | * Rules: 11 | * one → n is 1; 12 | * few → n is 0 or n mod 100 in 2..10; 13 | * many → n mod 100 in 11..19; 14 | * other → everything else 15 | * 16 | * Reference CLDR Version 1.9 beta (2010-11-16 21:48:45 GMT) 17 | * @see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 18 | * @see http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 19 | * @see plurals.xml (local copy) 20 | * 21 | * @package I18n_Plural 22 | * @category Plural Rules 23 | * @author Korney Czukowski 24 | * @copyright (c) 2011 Korney Czukowski 25 | * @license MIT License 26 | */ 27 | 28 | /** 29 | * Converted to Java by Sam Marshak, 2012 30 | */ 31 | public class PluralRules_Maltese extends PluralRules 32 | { 33 | public int quantityForNumber(int count) 34 | { 35 | int rem100 = count % 100; 36 | 37 | if (count == 1) 38 | { 39 | return QUANTITY_ONE; 40 | } 41 | else if (count == 0 || (rem100 >= 2 && rem100 <= 10)) 42 | { 43 | return QUANTITY_FEW; 44 | } 45 | else if (rem100 >= 11 && rem100 <= 19) 46 | { 47 | return QUANTITY_MANY; 48 | } 49 | else 50 | { 51 | return QUANTITY_OTHER; 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules_Lithuanian.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | /** 3 | * Plural rules for Lithuanian language 4 | * 5 | * Locales: lt 6 | * 7 | * Languages: 8 | * - Lithuanian (lt) 9 | * 10 | * Rules: 11 | * one → n mod 10 is 1 and n mod 100 not in 11..19; 12 | * few → n mod 10 in 2..9 and n mod 100 not in 11..19; 13 | * other → everything else 14 | * 15 | * Reference CLDR Version 1.9 beta (2010-11-16 21:48:45 GMT) 16 | * @see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 17 | * @see http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 18 | * @see plurals.xml (local copy) 19 | * 20 | * @package I18n_Plural 21 | * @category Plural Rules 22 | * @author Korney Czukowski 23 | * @copyright (c) 2011 Korney Czukowski 24 | * @license MIT License 25 | */ 26 | 27 | /** 28 | * Converted to Java by Sam Marshak, 2012 29 | */ 30 | public class PluralRules_Lithuanian extends PluralRules 31 | { 32 | public int quantityForNumber(int count) 33 | { 34 | int rem100 = count % 100; 35 | int rem10 = count % 10; 36 | 37 | if (rem10 == 1 && !(rem100 >= 11 && rem100 <= 19)) 38 | { 39 | return QUANTITY_ONE; 40 | } 41 | else if (rem10 >= 2 && rem10 <= 9 && !(rem100 >= 11 && rem100 <= 19)) 42 | { 43 | return QUANTITY_FEW; 44 | } 45 | else 46 | { 47 | return QUANTITY_OTHER; 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules_Welsh.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | /** 3 | * Plural rules for Welsh language: 4 | * 5 | * Locales: cy 6 | * 7 | * Languages: 8 | * - Welsh (cy) 9 | * 10 | * Rules: 11 | * zero → n is 0; 12 | * one → n is 1; 13 | * two → n is 2; 14 | * few → n is 3; 15 | * many → n is 6; 16 | * other → everything else 17 | * 18 | * Reference CLDR Version 1.9 beta (2010-11-16 21:48:45 GMT) 19 | * @see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 20 | * @see http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 21 | * @see plurals.xml (local copy) 22 | * 23 | * @package I18n_Plural 24 | * @category Plural Rules 25 | * @author Korney Czukowski 26 | * @copyright (c) 2011 Korney Czukowski 27 | * @license MIT License 28 | */ 29 | 30 | /** 31 | * Converted to Java by Sam Marshak, 2012 32 | */ 33 | public class PluralRules_Welsh extends PluralRules 34 | { 35 | public int quantityForNumber(int count) 36 | { 37 | if (count == 0) 38 | { 39 | return QUANTITY_ZERO; 40 | } 41 | else if (count == 1) 42 | { 43 | return QUANTITY_ONE; 44 | } 45 | else if (count == 2) 46 | { 47 | return QUANTITY_TWO; 48 | } 49 | else if (count == 3) 50 | { 51 | return QUANTITY_FEW; 52 | } 53 | else if (count == 6) 54 | { 55 | return QUANTITY_MANY; 56 | } 57 | else 58 | { 59 | return QUANTITY_OTHER; 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules_Arabic.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | /** 3 | * Plural rules for Arabic language 4 | * 5 | * Locales: ar 6 | * 7 | * Languages: 8 | * - Arabic (ar) 9 | * 10 | * Rules: 11 | * zero → n is 0; 12 | * one → n is 1; 13 | * two → n is 2; 14 | * few → n mod 100 in 3..10; 15 | * many → n mod 100 in 11..99; 16 | * other → everything else 17 | * 18 | * Reference CLDR Version 1.9 beta (2010-11-16 21:48:45 GMT) 19 | * @see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 20 | * @see http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 21 | * @see plurals.xml (local copy) 22 | * 23 | * @package I18n_Plural 24 | * @category Plural Rules 25 | * @author Korney Czukowski 26 | * @copyright (c) 2011 Korney Czukowski 27 | * @license MIT License 28 | */ 29 | 30 | /** 31 | * Converted to Java by Sam Marshak, 2012 32 | */ 33 | public class PluralRules_Arabic extends PluralRules 34 | { 35 | public int quantityForNumber(int count) 36 | { 37 | int rem100 = count % 100; 38 | 39 | if (count == 0) 40 | { 41 | return QUANTITY_ZERO; 42 | } 43 | else if (count == 1) 44 | { 45 | return QUANTITY_ONE; 46 | } 47 | else if (count == 2) 48 | { 49 | return QUANTITY_TWO; 50 | } 51 | else if (rem100 >= 3 && rem100 <= 10) 52 | { 53 | return QUANTITY_FEW; 54 | } 55 | else if (rem100 >= 11 && rem100 <= 99) 56 | { 57 | return QUANTITY_MANY; 58 | } 59 | else 60 | { 61 | return QUANTITY_OTHER; 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules_Breton.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | /** 3 | * Plural rules for Breton language: 4 | * 5 | * Locales: br 6 | * 7 | * Languages: 8 | * - Breton (br) 9 | * 10 | * Rules: 11 | * zero → n is 0; 12 | * one → n is 1; 13 | * two → n is 2; 14 | * few → n is 3; 15 | * many → n is 6; 16 | * other → everything else 17 | * 18 | * Note: for now, the rules are the same as with Welsh language, but according to the ticket 19 | * http://unicode.org/cldr/trac/ticket/2886 it's probably going to change 20 | * 21 | * Reference CLDR Version 1.9 beta (2010-11-16 21:48:45 GMT) 22 | * @see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 23 | * @see http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 24 | * @see plurals.xml (local copy) 25 | * 26 | * @package I18n_Plural 27 | * @category Plural Rules 28 | * @author Korney Czukowski 29 | * @copyright (c) 2011 Korney Czukowski 30 | * @license MIT License 31 | */ 32 | 33 | /** 34 | * Converted to Java by Sam Marshak, 2012 35 | */ 36 | public class PluralRules_Breton extends PluralRules 37 | { 38 | public int quantityForNumber(int count) 39 | { 40 | if (count == 0) 41 | { 42 | return QUANTITY_ZERO; 43 | } 44 | else if (count == 1) 45 | { 46 | return QUANTITY_ONE; 47 | } 48 | else if (count == 2) 49 | { 50 | return QUANTITY_TWO; 51 | } 52 | else if (count == 3) 53 | { 54 | return QUANTITY_FEW; 55 | } 56 | else if (count == 6) 57 | { 58 | return QUANTITY_MANY; 59 | } 60 | else 61 | { 62 | return QUANTITY_OTHER; 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules_None.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | /** 3 | * Plural rules for the following locales and languages: 4 | * 5 | * Locales: az bm fa ig hu ja kde kea ko my ses sg to tr vi wo yo zh bo dz id jv ka km kn ms th 6 | * 7 | * Languages: 8 | * Azerbaijani (az) 9 | * Bambara (bm) 10 | * Persian (fa) 11 | * Igbo (ig) 12 | * Hungarian (hu) 13 | * Japanese (ja) 14 | * Makonde (kde) 15 | * Kabuverdianu (kea) 16 | * Korean (ko) 17 | * Burmese (my) 18 | * Koyraboro Senni (ses) 19 | * Sango (sg) 20 | * Tonga (to) 21 | * Turkish (tr) 22 | * Vietnamese (vi) 23 | * Wolof (wo) 24 | * Yoruba (yo) 25 | * Chinese (zh) 26 | * Tibetan (bo) 27 | * Dzongkha (dz) 28 | * Indonesian (id) 29 | * Javanese (jv) 30 | * Georgian (ka) 31 | * Khmer (km) 32 | * Kannada (kn) 33 | * Malay (ms) 34 | * Thai (th) 35 | * 36 | * These are known to have no plurals, there are no rules: 37 | * other → everything 38 | * 39 | * Reference CLDR Version 1.9 beta (2010-11-16 21:48:45 GMT) 40 | * @see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 41 | * @see http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 42 | * @see plurals.xml (local copy) 43 | * 44 | * @package I18n_Plural 45 | * @category Plural Rules 46 | * @author Korney Czukowski 47 | * @copyright (c) 2011 Korney Czukowski 48 | * @license MIT License 49 | */ 50 | 51 | /** 52 | * Converted to Java by Sam Marshak, 2012 53 | */ 54 | public class PluralRules_None extends PluralRules 55 | { 56 | public int quantityForNumber(int count) 57 | { 58 | return QUANTITY_OTHER; 59 | } 60 | } -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules_Balkan.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | /** 3 | * Plural rules for the following locales and languages 4 | * 5 | * Locales: hr ru sr uk be bs sh 6 | * 7 | * Languages: 8 | * - Belarusian (br) 9 | * - Bosnian (bs) 10 | * - Croatian (hr) 11 | * - Russian (ru) 12 | * - Serbo-Croatian (sh) 13 | * - Serbian (sr) 14 | * - Ukrainian (uk) 15 | * 16 | * Rules: 17 | * one → n mod 10 is 1 and n mod 100 is not 11; 18 | * few → n mod 10 in 2..4 and n mod 100 not in 12..14; 19 | * many → n mod 10 is 0 or n mod 10 in 5..9 or n mod 100 in 11..14; 20 | * other → everything else (fractions) 21 | * 22 | * Reference CLDR Version 1.9 beta (2010-11-16 21:48:45 GMT) 23 | * @see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 24 | * @see http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 25 | * @see plurals.xml (local copy) 26 | * 27 | * @package I18n_Plural 28 | * @category Plural Rules 29 | * @author Korney Czukowski 30 | * @copyright (c) 2011 Korney Czukowski 31 | * @license MIT License 32 | */ 33 | 34 | /** 35 | * Converted to Java by Sam Marshak, 2012 36 | */ 37 | public class PluralRules_Balkan extends PluralRules 38 | { 39 | public int quantityForNumber(int count) 40 | { 41 | int rem100 = count % 100; 42 | int rem10 = count % 10; 43 | 44 | if (rem10 == 1 && rem100 != 11) 45 | { 46 | return QUANTITY_ONE; 47 | } 48 | else if (rem10 >= 2 && rem10 <= 4 && !(rem100 >= 12 && rem100 <= 14)) 49 | { 50 | return QUANTITY_FEW; 51 | } 52 | else if (rem10 == 0 || (rem10 >= 5 && rem10 <= 9) || (rem100 >= 11 && rem100 <= 14)) 53 | { 54 | return QUANTITY_MANY; 55 | } 56 | else 57 | { 58 | return QUANTITY_OTHER; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 18 | 19 | 26 | 27 | 34 | 35 | 36 | 37 | 40 | 41 | 45 | 46 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules_One.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | /** 3 | * Plural rules for the following locales and languages: 4 | * 5 | * Locales: bem brx da de el en eo es et fi fo gl he iw it nb nl nn no pt_PT sv af bg bn ca eu fur fy gu ha is ku lb ml 6 | * mr nah ne om or pa pap ps so sq sw ta te tk ur zu mn gsw chr rm pt 7 | * (in original order) 8 | * 9 | * Languages: 10 | * Afrikaans (af) 11 | * Bemba (bem) 12 | * Bulgarian (bg) 13 | * Bodo (brx) 14 | * Bengali (bn) 15 | * Catalan (ca) 16 | * Cherokee (chr) 17 | * Danish (da) 18 | * German (de) 19 | * Greek (el) 20 | * English (en) 21 | * Esperanto (eo) 22 | * Spanish (es) 23 | * Estonian (et) 24 | * Basque (eu) 25 | * Finnish (fi) 26 | * Faroese (fo) 27 | * Friulian (fur) 28 | * Western Frisian (fy) 29 | * Galician (gl) 30 | * Swiss German (gsw) 31 | * Gujarati (gu) 32 | * Hausa (ha) 33 | * Hebrew (he) 34 | * Icelandic (is) 35 | * Italian (it) 36 | * iw (iw) 37 | * Kurdish (ku) 38 | * Luxembourgish (lb) 39 | * Malayalam (ml) 40 | * Mongolian (mn) 41 | * Marathi (mr) 42 | * Nahuatl (nah) 43 | * Norwegian Bokmål (nb) 44 | * Nepali (ne) 45 | * Dutch (nl) 46 | * Norwegian Nynorsk (nn) 47 | * Norwegian (no) 48 | * Oromo (om) 49 | * Oriya (or) 50 | * Punjabi (pa) 51 | * Papiamento (pap) 52 | * Pashto (ps) 53 | * Portuguese (pt) 54 | * Romansh (rm) 55 | * Somali (so) 56 | * Albanian (sq) 57 | * Swedish (sv) 58 | * Swahili (sw) 59 | * Tamil (ta) 60 | * Telugu (te) 61 | * Turkmen (tk) 62 | * Urdu (ur) 63 | * Zulu (zu) 64 | * 65 | * Rules: 66 | * one → n is 1; 67 | * other → everything else 68 | * 69 | * Reference CLDR Version 1.9 beta (2010-11-16 21:48:45 GMT) 70 | * @see http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html 71 | * @see http://unicode.org/repos/cldr/trunk/common/supplemental/plurals.xml 72 | * @see plurals.xml (local copy) 73 | * 74 | * @package I18n_Plural 75 | * @category Plural Rules 76 | * @author Korney Czukowski 77 | * @copyright (c) 2011 Korney Czukowski 78 | * @license MIT License 79 | * 80 | */ 81 | 82 | /** 83 | * Converted to Java by Sam Marshak, 2012 84 | */ 85 | public class PluralRules_One extends PluralRules 86 | { 87 | public int quantityForNumber(int count) 88 | { 89 | return count == 1 ? QUANTITY_ONE : QUANTITY_OTHER; 90 | } 91 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | group = 'com.seppius.plurals' 2 | version = '1.1' 3 | 4 | buildscript { 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:0.12.2' 10 | } 11 | } 12 | apply plugin: 'com.android.library' 13 | 14 | dependencies { 15 | } 16 | 17 | android { 18 | compileSdkVersion 19 19 | buildToolsVersion '19.1.0' 20 | } 21 | 22 | // Publish to maven repository 23 | apply plugin: 'maven' 24 | 25 | task libJar(type: Jar) { 26 | from fileTree(dir: 'build/classes/release') 27 | } 28 | 29 | task sourcesJar(type: Jar) { 30 | classifier 'sources' 31 | from android.sourceSets.main.java.srcDirs 32 | } 33 | 34 | artifacts { 35 | archives libJar 36 | archives sourcesJar 37 | } 38 | 39 | uploadArchives { 40 | repositories { 41 | mavenDeployer { 42 | repository(url: "file://$buildDir/mvnRepo/") 43 | /* 44 | repository(url: "${bintray_api_base_url}/maven/${bintray_org}/${bintray_repo}/${bintray_package}") { 45 | authentication(userName: bintray_username, password: bintray_api_key) 46 | } 47 | */ 48 | pom.project { 49 | artifactId = 'android-i18n-plurals' 50 | name = 'android-i18n-plurals' 51 | packaging = 'jar' 52 | description = 'Alternative handling of Android Quantity Strings (Plurals)' 53 | url 'https://code.google.com/p/android-i18n-plurals/' 54 | 55 | scm { 56 | url 'git:git@github.com:populov/android-i18n-plurals.git' 57 | connection 'scm:git:git@github.com:populov/android-i18n-plurals.git' 58 | developerConnection 'scm:git:git@github.com:populov/android-i18n-plurals.git' 59 | } 60 | 61 | /* 62 | scm { 63 | url 'https://code.google.com/p/android-i18n-plurals/source' 64 | connection 'http://android-i18n-plurals.googlecode.com/svn/trunk/' 65 | developerConnection 'http://android-i18n-plurals.googlecode.com/svn/trunk/' 66 | } 67 | */ 68 | 69 | licenses { 70 | license { 71 | name = 'The MIT License (MIT)' 72 | url 'http://opensource.org/licenses/MIT' 73 | distribution 'repo' 74 | } 75 | } 76 | 77 | developers { 78 | developer { 79 | id 'MarinaSeppius' 80 | name = 'Marina Seppius' 81 | email 'MarinaSeppius@gmail.com' 82 | } 83 | } 84 | } 85 | } 86 | } 87 | } 88 | 89 | -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralResources.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | import java.lang.reflect.Method; 5 | import java.util.Locale; 6 | 7 | import android.content.res.Resources; 8 | import android.content.res.Resources.*; 9 | 10 | @SuppressWarnings("nls") 11 | public class PluralResources 12 | { 13 | private Resources resources; 14 | private Method getResourceBagTextMethod; 15 | private PluralRules rules; 16 | private String language; 17 | private boolean treatZero = true; 18 | 19 | public PluralResources( Resources resources ) throws SecurityException, NoSuchMethodException 20 | { 21 | this.resources = resources; 22 | getResourceBagTextMethod = resources.getAssets().getClass().getDeclaredMethod("getResourceBagText", int.class, int.class); 23 | getResourceBagTextMethod.setAccessible(true); 24 | } 25 | 26 | public void setTreatZero( boolean treatZero ) 27 | { 28 | this.treatZero = treatZero; 29 | } 30 | 31 | /** 32 | * Return the string value associated with a particular resource ID for a particular 33 | * numerical quantity, substituting the format arguments as defined in 34 | * {@link java.util.Formatter} and {@link java.lang.String#format}. It will be 35 | * stripped of any styled text information. 36 | * 37 | * @param id The desired resource identifier, as generated by the aapt 38 | * tool. This integer encodes the package, type, and resource 39 | * entry. The value 0 is an invalid identifier. 40 | * @param quantity The number used to get the correct string for the current language's 41 | * plural rules. 42 | * @param formatArgs The format arguments that will be used for substitution. 43 | * 44 | * @throws NotFoundException Throws NotFoundException if the given ID does not exist. 45 | * 46 | * @return String The string data associated with the resource, 47 | * stripped of styled text information. 48 | */ 49 | public String getQuantityString(int id, int quantity, Object... formatArgs) throws NotFoundException 50 | { 51 | return String.format(resources.getConfiguration().locale, getQuantityString(id, quantity), formatArgs); 52 | } 53 | 54 | public String getQuantityString( int id, int quantity ) throws NotFoundException 55 | { 56 | // Android 3.0 and later have fixed the problem with plurals, 57 | // may consider to use system function, will lose special handling of ZERO though 58 | // if ( Build.SDK_INT >= 11 ) 59 | // return resources.getQuantityString(id, quantity); 60 | 61 | Locale locale = Locale.getDefault(); 62 | if ( !locale.getLanguage().equals(language)) 63 | { 64 | language = locale.getLanguage(); 65 | rules = PluralRules.ruleForLocale(locale); 66 | } 67 | 68 | if ( rules == null ) 69 | return resources.getQuantityString(id, quantity); 70 | 71 | if ( getResourceBagTextMethod == null ) 72 | throw new IllegalArgumentException(); 73 | 74 | Object format = null; 75 | try 76 | { 77 | // special case -- if translator added special rule for ZERO we disregard language rules 78 | if ( quantity == 0 && treatZero ) 79 | format = getResourceBagTextMethod.invoke(resources.getAssets(), id, PluralRules.ID_ZERO); 80 | 81 | if ( format == null ) 82 | format = getResourceBagTextMethod.invoke(resources.getAssets(), id, PluralRules.attrForQuantity(rules.quantityForNumber(quantity))); 83 | 84 | if ( format == null ) 85 | format = getResourceBagTextMethod.invoke(resources.getAssets(), id, PluralRules.ID_OTHER); 86 | 87 | } catch (IllegalArgumentException e) { 88 | throw new NotFoundException(e.getMessage()); 89 | } catch (IllegalAccessException e) { 90 | throw new NotFoundException(e.getMessage()); 91 | } catch (InvocationTargetException e) { 92 | throw new NotFoundException(e.getMessage()); 93 | } 94 | 95 | if ( format == null ) 96 | { 97 | throw new android.content.res.Resources.NotFoundException("Plural resource ID #0x" + Integer.toHexString(id) 98 | + " quantity=" + quantity 99 | + " item=" + PluralRules.stringForQuantity(rules.quantityForNumber(quantity))); 100 | } 101 | 102 | return format.toString(); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is a clone of [android-i18n-plurals](https://code.google.com/p/android-i18n-plurals/) project, adapted for Gradle build and Maven artifact publishing. 2 | 3 | android-i18n-plurals 4 | ==================== 5 | Android has great built in support for plural forms that represent different quantities. It is well documented in [this section](http://developer.android.com/guide/topics/resources/string-resource.html#Plurals) of API reference. 6 | 7 | Unfortunately, it seems that on early Android versions (API Level 10 and below) the plurals support does not cover all languages. 8 | 9 | For example if you specify the following block in your strings.xml file for Russian language 10 | 11 | ```xml 12 | 13 | %d попугай 14 | %d попугая 15 | %d попугаев 16 | %d попугаев 17 | 18 | ``` 19 | 20 | it would produce the following results for quantities from 0 to 6: 21 | 22 | 0 попугаев 23 | 1 попугай 24 | 2 попугаев 25 | 3 попугаев 26 | 4 попугаев 27 | 5 попугаев 28 | 6 попугаев 29 | As you see, quantities of 2, 3, and 4 are handled incorrectly. 30 | 31 | This project provides proper pluralization for all languages. 32 | 33 | Use PluralResources class that implements getQuantityString() method. The syntax of this getQuantityString() is the same as APIs Resources [getQuantityString()](http://developer.android.com/reference/android/content/res/Resources.html#getQuantityString%28int,%20int%29), so it is easy to replace in existing projects. 34 | 35 | For the example above, the output would be the following: 36 | 37 | 0 попугаев 38 | 1 попугай 39 | 2 попугая 40 | 3 попугая 41 | 4 попугая 42 | 5 попугаев 43 | 6 попугаев 44 | One of the possible use models is to declare static PluralResources field, and initialize it in Applications onCreate(): 45 | 46 | ```java 47 | public class MyApplication extends Application 48 | { 49 | public static PluralResources pluralResources; 50 | 51 | @Override 52 | public void onCreate() 53 | { 54 | super.onCreate(); 55 | 56 | try { 57 | pluralResources = new PluralResources( getResources() ); 58 | } catch (SecurityException e1) { 59 | // TODO Auto-generated catch block 60 | e1.printStackTrace(); 61 | } catch (NoSuchMethodException e1) { 62 | // TODO Auto-generated catch block 63 | e1.printStackTrace(); 64 | } 65 | ``` 66 | 67 | to use it just call 68 | 69 | ```java 70 | MyApplication.pluralResources.getQuantityString(R.plurals.parrot_count, n, n ); 71 | ``` 72 | (if you use this method do not forget to add MyApplication to your AndroidManifest.xml) 73 | 74 | -------- 75 | Keywords "zero", "one", "two", "few", "many", and "other" you specify in strings.xml are different plural form types, not the literal values, sometimes has little to do with actual quantities. The meanings of these keywords is different for different languages, see this table for all rules. 76 | 77 | -------- 78 | In addition to proper pluralization the PluralResources class provides an option for special handling of the 0 quantity. If you specify the case for "zero" in your resource, this would be used for the 0 quantity unconditionally, regardless of whether or not the language you are writing the resource for has special treatment for "zero". That is, for instance, if you have 79 | 80 | ```xml 81 | No parrots 82 | ``` 83 | for English, then this would be used, despite the fact that English does not have special plural form for zero. 84 | 85 | -------- 86 | Note 87 | ---- 88 | Android API 11 and higher has proper support for all languages, so **if your minSdkVersion is 11 then you do not need this**. 89 | Use in Android Studio 90 | -------------- 91 | ### Online dependency ### 92 | The easyest way to use - you don't need to build project yourself, just add a few lines in your *gradle.config*. 93 | 94 | 1. Add maven repository in project repositories section (*don't mix it up with buildscript repositories, that usually goes first*). 95 | 96 | ```groovy 97 | repositories { 98 | mavenCentral() 99 | maven { url "http://dl.bintray.com/populov/maven" } 100 | } 101 | ``` 102 | 103 | 2. Add project depencency as usual. 104 | 105 | ```groovy 106 | dependencies { 107 | compile 'com.seppius.plurals:android-i18n-plurals:1.+' 108 | ... 109 | } 110 | ``` 111 | -------------------------------------------------------------------------------- /sample/src/main/java/com/seppius/plurals/test/TestPluralsActivity.java: -------------------------------------------------------------------------------- 1 | package com.seppius.plurals.test; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Locale; 5 | 6 | import com.seppius.i18n.plurals.PluralResources; 7 | 8 | import android.app.Activity; 9 | import android.content.res.Configuration; 10 | import android.os.Bundle; 11 | import android.util.Log; 12 | import android.widget.AdapterView; 13 | import android.widget.ArrayAdapter; 14 | import android.widget.Spinner; 15 | import android.widget.TextView; 16 | 17 | public class TestPluralsActivity extends Activity 18 | { 19 | private static final int TESTS_COUNT = 123; 20 | 21 | @Override 22 | public void onCreate(Bundle savedInstanceState) 23 | { 24 | super.onCreate(savedInstanceState); 25 | setContentView(R.layout.main); 26 | 27 | selectLanguage(Locale.getDefault().getLanguage()); 28 | 29 | class LanguageDesciptor 30 | { 31 | String name; 32 | String code; 33 | 34 | LanguageDesciptor(String name, String code) 35 | { 36 | this.name = name; 37 | this.code = code; 38 | } 39 | 40 | public String toString( ) 41 | { 42 | return name + " (" + code + ")"; 43 | } 44 | } 45 | 46 | final ArrayList languages = new ArrayList(); 47 | languages.add( new LanguageDesciptor("English" , "en") ); // PluralRules_One 48 | //languages.add( new LanguageDesciptor("French" , "fr") ); // PluralRules_French 49 | //languages.add( new LanguageDesciptor("Czech" , "cs") ); // PluralRules_Czech 50 | languages.add( new LanguageDesciptor("Russian" , "ru") ); // PluralRules_Balkan 51 | //languages.add( new LanguageDesciptor("Latvian" , "lv") ); // PluralRules_Latvian 52 | //languages.add( new LanguageDesciptor("Lithuanian" , "lt") ); // PluralRules_Lithuanian 53 | //languages.add( new LanguageDesciptor("Irish" , "ga") ); // PluralRules_Two 54 | //languages.add( new LanguageDesciptor("Hindi" , "hi") ); // PluralRules_Zero 55 | //languages.add( new LanguageDesciptor("Thai" , "th") ); // PluralRules_None 56 | //languages.add( new LanguageDesciptor("Arabic" , "ar") ); // PluralRules_Arabic 57 | 58 | Spinner spinner = (Spinner) findViewById(R.id.spinner); 59 | ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, languages.toArray(new LanguageDesciptor [languages.size()])); 60 | adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 61 | spinner.setAdapter(adapter); 62 | 63 | spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() 64 | { 65 | @Override 66 | public void onItemSelected(AdapterView parent, android.view.View view, int position, long selected) 67 | { 68 | selectLanguage( languages.get(position).code ); 69 | } 70 | 71 | @Override 72 | public void onNothingSelected(AdapterView parent) 73 | { 74 | } 75 | }); 76 | 77 | spinner.setSelection(1); 78 | 79 | } 80 | 81 | private void selectLanguage( String language ) 82 | { 83 | Configuration config = getResources().getConfiguration(); 84 | 85 | Locale locale = new Locale(language); 86 | Locale.setDefault(locale); 87 | config.locale = locale; 88 | getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); 89 | 90 | StringBuilder text_after = new StringBuilder(); 91 | StringBuilder text_before = new StringBuilder(); 92 | 93 | PluralResources plural_resources; 94 | try 95 | { 96 | plural_resources = new PluralResources(getResources()); 97 | } 98 | catch (SecurityException e) 99 | { 100 | Log.e("", "result:" + e ); 101 | e.printStackTrace(); 102 | return; 103 | } 104 | catch (NoSuchMethodException e) 105 | { 106 | Log.e("", "result:" + e ); 107 | e.printStackTrace(); 108 | return; 109 | } 110 | 111 | for ( int i = 0; i <= TESTS_COUNT; i++ ) 112 | { 113 | try 114 | { 115 | text_after.append( plural_resources.getQuantityString( R.plurals.parrot_count, i, i) ); 116 | } 117 | catch (android.content.res.Resources.NotFoundException e) 118 | { 119 | Log.e("", "result:" + e ); 120 | e.printStackTrace(); 121 | text_after.append( e.getMessage() ); 122 | } 123 | text_after.append("\n"); 124 | 125 | text_before.append(getResources().getQuantityString( R.plurals.parrot_count, i, i )); 126 | text_before.append("\n"); 127 | } 128 | 129 | TextView text_before_view = (TextView)findViewById(R.id.text_before); 130 | text_before_view.setText(text_before); 131 | 132 | TextView text_after_view = (TextView)findViewById(R.id.text_after); 133 | text_after_view.setText(text_after); 134 | } 135 | } -------------------------------------------------------------------------------- /library/src/main/java/com/seppius/i18n/plurals/PluralRules.java: -------------------------------------------------------------------------------- 1 | package com.seppius.i18n.plurals; 2 | 3 | /* 4 | * Copyright (C) 2007 The Android Open Source Project 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 | 19 | import java.util.HashMap; 20 | import java.util.Locale; 21 | import java.util.Map; 22 | 23 | /* 24 | * Yuck-o. This is not the right way to implement this. When the ICU PluralRules 25 | * object has been integrated to android, we should switch to that. For now, yuck-o. 26 | */ 27 | 28 | @SuppressWarnings("nls") 29 | abstract public class PluralRules 30 | { 31 | static final int QUANTITY_OTHER = 0x0000; 32 | static final int QUANTITY_ZERO = 0x0001; 33 | static final int QUANTITY_ONE = 0x0002; 34 | static final int QUANTITY_TWO = 0x0004; 35 | static final int QUANTITY_FEW = 0x0008; 36 | static final int QUANTITY_MANY = 0x0010; 37 | 38 | static final int ID_OTHER = 0x01000004; 39 | static final int ID_ZERO = 0x01000005; 40 | 41 | abstract int quantityForNumber(int n); 42 | 43 | final int attrForNumber(int n) { 44 | return PluralRules.attrForQuantity(quantityForNumber(n)); 45 | } 46 | 47 | static final int attrForQuantity(int quantity) { 48 | // see include/utils/ResourceTypes.h 49 | switch (quantity) { 50 | case QUANTITY_ZERO: return ID_ZERO; 51 | case QUANTITY_ONE: return 0x01000006; 52 | case QUANTITY_TWO: return 0x01000007; 53 | case QUANTITY_FEW: return 0x01000008; 54 | case QUANTITY_MANY: return 0x01000009; 55 | default: return ID_OTHER; 56 | } 57 | } 58 | 59 | static final String stringForQuantity(int quantity) { 60 | switch (quantity) { 61 | case QUANTITY_ZERO: 62 | return "zero"; 63 | case QUANTITY_ONE: 64 | return "one"; 65 | case QUANTITY_TWO: 66 | return "two"; 67 | case QUANTITY_FEW: 68 | return "few"; 69 | case QUANTITY_MANY: 70 | return "many"; 71 | default: 72 | return "other"; 73 | } 74 | } 75 | 76 | 77 | private static Map allRules = new HashMap(); 78 | 79 | static 80 | { 81 | addRules( new String [] {"bem", "brx", "da", "de", "el", "en", "eo", "es", "et", "fi", "fo", "gl", "he", "iw", "it", "nb", 82 | "nl", "nn", "no", "sv", "af", "bg", "bn", "ca", "eu", "fur", "fy", "gu", "ha", "is", "ku", 83 | "lb", "ml", "mr", "nah", "ne", "om", "or", "pa", "pap", "ps", "so", "sq", "sw", "ta", "te", 84 | "tk", "ur", "zu", "mn", "gsw", "chr", "rm", "pt"}, new PluralRules_One()); 85 | addRules( new String [] {"cs", "sk"}, new PluralRules_Czech()); 86 | addRules( new String [] {"ff", "fr", "kab"}, new PluralRules_French()); 87 | addRules( new String [] {"hr", "ru", "sr", "uk", "be", "bs", "sh"}, new PluralRules_Balkan()); 88 | addRules( new String [] {"lv"}, new PluralRules_Latvian()); 89 | addRules( new String [] {"lt"}, new PluralRules_Lithuanian()); 90 | addRules( new String [] {"pl"}, new PluralRules_Polish()); 91 | addRules( new String [] {"ro", "mo"}, new PluralRules_Romanian()); 92 | addRules( new String [] {"sl"}, new PluralRules_Slovenian()); 93 | addRules( new String [] {"ar"}, new PluralRules_Arabic()); 94 | addRules( new String [] {"mk"}, new PluralRules_Macedonian()); 95 | addRules( new String [] {"cy"}, new PluralRules_Welsh()); 96 | addRules( new String [] {"br"}, new PluralRules_Breton()); 97 | addRules( new String [] {"lag"}, new PluralRules_Langi()); 98 | addRules( new String [] {"shi"}, new PluralRules_Tachelhit()); 99 | addRules( new String [] {"mt"}, new PluralRules_Maltese()); 100 | addRules( new String [] {"ga", "se", "sma", "smi", "smj", "smn", "sms"}, new PluralRules_Two()); 101 | addRules( new String [] {"ak", "am", "bh", "fil", "tl", "guw", "hi", "ln", "mg", "nso", "ti", "wa"}, new PluralRules_Zero()); 102 | addRules( new String [] {"az", "bm", "fa", "ig", "hu", "ja", "kde", "kea", "ko", "my", "ses", "sg", "to", 103 | "tr", "vi", "wo", "yo", "zh", "bo", "dz", "id", "jv", "ka", "km", "kn", "ms", "th"}, new PluralRules_None()); 104 | } 105 | 106 | public static void addRules( String [] languages, PluralRules rules ) { 107 | for ( String language : languages ) 108 | allRules.put(language, rules); 109 | } 110 | 111 | public static void addRules( String language, PluralRules rules ) { 112 | allRules.put(language, rules); 113 | } 114 | 115 | static final PluralRules ruleForLocale(Locale locale) { 116 | 117 | return allRules.get(locale.getLanguage()); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------