[go: nahoru, domu]

Skip to content

Commit

Permalink
replace plurals with a utility method
Browse files Browse the repository at this point in the history
  • Loading branch information
maxme committed Mar 10, 2016
1 parent 9cd77b6 commit b2ac4fe
Showing 1 changed file with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.wordpress.android.util;

import android.content.Context;
import android.support.annotation.StringRes;
import android.text.Html;
import android.text.TextUtils;

Expand Down Expand Up @@ -63,7 +65,7 @@ public static String addPTags(String source) {
String trimmed = asploded[i].trim();
if (trimmed.length() > 0) {
trimmed = trimmed.replace("<br />", "<br>").replace("<br/>", "<br>").replace("<br>\n", "<br>")
.replace("\n", "<br>");
.replace("\n", "<br>");
wrappedHTML.append("<p>");
wrappedHTML.append(trimmed);
wrappedHTML.append("</p>");
Expand Down Expand Up @@ -186,7 +188,7 @@ public static String removeTrailingSlash(final String str) {
return str;
}

return str.substring(0, str.length() -1);
return str.substring(0, str.length() - 1);
}

/*
Expand Down Expand Up @@ -223,14 +225,13 @@ public static String replaceUnicodeSurrogateBlocksWithHTMLEntities(final String
* Used to convert a language code ([lc]_[rc] where lc is language code (en, fr, es, etc...)
* and rc is region code (zh-CN, zh-HK, zh-TW, etc...) to a displayable string with the languages
* name.
*
* <p/>
* The input string must be between 2 and 6 characters, inclusive. An empty string is returned
* if that is not the case.
*
* <p/>
* If the input string is recognized by {@link Locale} the result of this method is the given
*
* @return
* non-null
* @return non-null
*/
public static String getLanguageString(String languagueCode, Locale displayLocale) {
if (languagueCode == null || languagueCode.length() < 2 || languagueCode.length() > 6) {
Expand Down Expand Up @@ -262,11 +263,11 @@ public static final String stripNonValidXMLCharacters(String in) {
for (int i = 0; i < in.length(); i++) {
current = in.charAt(i); // NOTE: No IndexOutOfBoundsException caught here; it should not happen.
if ((current == 0x9) ||
(current == 0xA) ||
(current == 0xD) ||
((current >= 0x20) && (current <= 0xD7FF)) ||
((current >= 0xE000) && (current <= 0xFFFD)) ||
((current >= 0x10000) && (current <= 0x10FFFF))) {
(current == 0xA) ||
(current == 0xD) ||
((current >= 0x20) && (current <= 0xD7FF)) ||
((current >= 0xE000) && (current <= 0xFFFD)) ||
((current >= 0x10000) && (current <= 0x10FFFF))) {
out.append(current);
}
}
Expand All @@ -279,6 +280,7 @@ public static final String stripNonValidXMLCharacters(String in) {
public static int stringToInt(String s) {
return stringToInt(s, 0);
}

public static int stringToInt(String s, int defaultValue) {
if (s == null)
return defaultValue;
Expand All @@ -292,6 +294,7 @@ public static int stringToInt(String s, int defaultValue) {
public static long stringToLong(String s) {
return stringToLong(s, 0L);
}

public static long stringToLong(String s, long defaultValue) {
if (s == null)
return defaultValue;
Expand All @@ -301,4 +304,18 @@ public static long stringToLong(String s, long defaultValue) {
return defaultValue;
}
}

/**
* We need this because our translation platform doesn't support plurals.
*/
public static String getQuantityString(Context context, @StringRes int zero, @StringRes int one,
@StringRes int other, int count) {
if (count == 0) {
return context.getString(zero);
}
if (count == 1) {
return context.getString(one);
}
return context.getString(other, count);
}
}

0 comments on commit b2ac4fe

Please sign in to comment.