square / phrase Goto Github PK
View Code? Open in Web Editor NEWPhrase is an Android string resource templating library
License: Apache License 2.0
Phrase is an Android string resource templating library
License: Apache License 2.0
ListPhrase listFormatter = ListPhrase.from(" and ", ", ", and ");
String[] texts=new String[]{"Joe", "Jane", "John"};
ArrayList<CharSequence> bolds=new new ArrayList<>();
for(String t : texts){
Spannable b = new SpannableString(t);
boldString.setSpan(new StyleSpan(BOLD), 0, t.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
bolds.add(b)
}
return listFormatter.join(bolds)
That doesn't show style while Phrase support for Spannable
Hi there,
The following string and the invocation of Phrase got me this exception every time. Could someone take a look and tell me what went wrong? Thanks! :
<string name="example_string">{aaa} (Now {bbb})</string>
Phrase.from(this, R.string.example_string)
.put("aaa", getAaa())
.put("bbb", getBbb())
.format()
This is the exception:
Exploded trying to parse content: java.lang.IllegalArgumentException: Missing closing brace: }
at com.squareup.phrase.Phrase.key(Phrase.java:245)
at com.squareup.phrase.Phrase.token(Phrase.java:221)
at com.squareup.phrase.Phrase.<init>(Phrase.java:204)
at com.squareup.phrase.Phrase.from(Phrase.java:112)
at com.squareup.phrase.Phrase.from(Phrase.java:103)
at com.squareup.phrase.Phrase.from(Phrase.java:94)
It's occasionally useful to be able to populate the Phrase parameter set without having access to Resources
, and actually load the template and bind the parameters late. The current API does not support this well.
Now it's only support "{" and "}", hope to custom prefix and suffix
Hey! This looks pretty great, and I wanted to propose adding an interceptor API of sorts to allow for dynamic configuration of strings as they come through. This would allow for experimentation with copy pretty easily, as well as anything else people might come up with a need for.
keyCamelCase -> fails
key_camel_case -> accepted
How do you handle "1 Beer" vs "3 Beers" with this library? Is there any special code for that or is something like that planned?
Please, add in readme info that keys must be lowercase
Hi,
I'm getting a crash when using Phrase.from("This is an {EXAMPLE}");
Throwing a 'Unexpected character 'E'; expected key.'
Could you add support for uppercase keys? It would help me since i'm not controlling the strings I receive.
Thank you !
CharSequence formatted = Phrase.from("Hi {first_name}, you are {orderBy} years old.")
.put("first_name", firstName)
.put("orderBy", age)
.format();
when the string contains 'orderBy' it Throw IllegalArgumentException: Missing closing brace: }
Looks like this it's caused by only checking for letters and underscores in
private KeyToken key(Token prev){
....
while ((curChar >= 'a' && curChar <= 'z') || curChar == '_') {
sb.append(curChar);
consume();
}
...
}
Seeing as Jetpack Compose is the new hotness, it would be great to have support for building AnnotatedString
s. Options:
phrase2
and include Compose in that artifact. If somehow there are bugs that need to get fixed, in theory we can do a release of both artifactsphrase-compose
artifact, make keys
/keysToValues
public, and add a method in the new artifact that reads them and builds an AnnotatedString
We should at least call out in the docs that Phrase.put(String, int) uses the value of the int as a string, rather than grabbing a string from resources. Many Android views have interchangeable methods like setText(String) and setText(int) that could mislead a user of this library.
I don't have great suggestions of a more concrete fix. Maybe rename to putInt(String, int)
but that seems ugly.
Something like this?
<string name="xx"><color="@color/color_id">{a}</color> is {b}<color="#aabbcc">awesome?</color></string>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.