SRML stands for String Resource Markup Language
Keeping your text in <string> resources is important when it comes time to internationalize your app (or just keep the code clean).
SRML Tags
-
{{b}}Text{{/b}}-> Text -
{{i}}Text{{/i}}-> Text -
{{u}}Text{{/u}}-> underlined text (markdown fail!) -
{{strike}}Text{{/strike}}->Text -
{{color fg=#FF0000}}Text{{/color}}-> red "Text" -
{{color bg=#FF0000}}Text{{/color}}-> red background "Text" -
{{color fg=#fff bg=#000}}Text{{/color}}-> white "Text" on black background -
{{link url=http://myurl.com}}Text{{/link}}-> Test -
{{code}}Text{{/code}}-> monospaced text -
{{intent class=com.yourcompany.ActivityClass}}Text{{/intent}}-> link "Text" which launches theActivityClassactivity -
{{intent class=com.yourcompany.ActivityClass x_myextra=foo}}Text{{/intent}}-> link "Text" which launches theActivityClassactivity with intent extramyextra="foo" -
{{intent class=com.yourcompany.ActivityClass x_myextra=`value with spaces`}}Text{{/intent}}-> link "Text" which launches theActivityClassactivity with intent extramyextra="value with spaces" -
{{intent class=com.yourcompany.ServiceClass for_service=true}}Text{{/intent}}-> link "Text" which starts theServiceClassservice
Create your own tags
- Extend Tag or ParameterizedTag
- Register your tag with
SRML.registerTag("mytag", MyTag.class) - Use it in a string resource:
<string name="some_string">Hello {{mytag}}World{{/mytag}}</string>
Setup
Add jitpack.io to your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}Add SRML as a dependency to your app's build.gradle:
dependencies {
compile 'com.github.jasonwyatt:SRML:-SNAPSHOT'
}How to use
// simple case
SRML.getString(context, R.string.mystring);
// parameterized strings
SRML.getString(context, R.string.my_parameterized_string, firstArg, secondArg, ...);
// quantity strings
SRML.getQuantityString(context, R.plurals.my_plurals_resource, quantity, ...format args...);
// String array resources
SRML.getStringArray(context, R.array.my_string_array);Your resources can be arbitrarily complex, involving multiple, nested tags.
License
Copyright 2016 Jason Feinstein
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.