Skip to content

Commit

Permalink
Added Phrase.fromPlural()
Browse files Browse the repository at this point in the history
Just a small convenience for deriving Phrase instances from
<plurals> tags.
  • Loading branch information
dlew committed Feb 16, 2016
1 parent c461cd3 commit a19c965
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/java/com/squareup/phrase/Phrase.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.app.Fragment;
import android.content.Context;
import android.content.res.Resources;
import android.support.annotation.PluralsRes;
import android.support.annotation.StringRes;
import android.text.SpannableStringBuilder;
import android.view.View;
Expand Down Expand Up @@ -104,6 +105,33 @@ public static Phrase from(Resources r, @StringRes int patternResourceId) {
return from(r.getText(patternResourceId));
}

/**
* Entry point into this API.
*
* @throws IllegalArgumentException if pattern contains any syntax errors.
*/
public static Phrase fromPlural(View v, @PluralsRes int patternResourceId, int quantity) {
return fromPlural(v.getResources(), patternResourceId, quantity);
}

/**
* Entry point into this API.
*
* @throws IllegalArgumentException if pattern contains any syntax errors.
*/
public static Phrase fromPlural(Context c, @PluralsRes int patternResourceId, int quantity) {
return fromPlural(c.getResources(), patternResourceId, quantity);
}

/**
* Entry point into this API.
*
* @throws IllegalArgumentException if pattern contains any syntax errors.
*/
public static Phrase fromPlural(Resources r, @PluralsRes int patternResourceId, int quantity) {
return from(r.getQuantityText(patternResourceId, quantity));
}

/**
* Entry point into this API; pattern must be non-null.
*
Expand Down

0 comments on commit a19c965

Please sign in to comment.