public class CompileStringsStep extends Object implements Step
Step
takes a list of string resource files (strings.xml), groups them by locales,
and for each locale generates a file with all the string resources for that locale. Strings.xml
files without a resource qualifier are mapped to the "en" locale.
A typical strings.xml file looks like:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="resource_name1">I am a string.</string>
<string name="resource_name2">I am another string.</string>
<plurals name="time_hours_ago">
<item quantity="one">1 minute ago</item>
<item quantity="other">%d minutes ago</item>
</plurals>
<string-array name="logging_levels">
<item>Default</item>
<item>Verbose</item>
<item>Debug</item>
</string-array>
</resources>
For more information on the xml file format, refer to: String Resources - Android Developers
So for each supported locale in a project, this step goes through all such xml files for that locale, and builds a map of resource name to resource value, where resource value is either:
StringResources
for the file format.Constructor and Description |
---|
CompileStringsStep(ProjectFilesystem filesystem,
com.google.common.collect.ImmutableList<Path> stringFiles,
Path rDotTxtFile,
java.util.function.Function<String,Path> pathBuilder)
Note: The ordering of files in the input list determines which resource value ends up in the
output .fbstr file, in the event of multiple xml files of a locale sharing the same string
resource name - file that appears first in the list wins.
|
Modifier and Type | Method and Description |
---|---|
static void |
buildResourceNameToIdMap(ProjectFilesystem filesystem,
Path pathToRDotTxtFile,
Map<String,Integer> stringResourceNameToIdMap,
Map<String,Integer> pluralsResourceNameToIdMap,
Map<String,Integer> arrayResourceNameToIdMap)
Parses the R.txt file generated by aapt, looks for resources of type
string , plurals and array , and builds a map of resource names to their corresponding ids. |
StepExecutionResult |
execute(ExecutionContext context) |
String |
getDescription(ExecutionContext context) |
String |
getShortName() |
public CompileStringsStep(ProjectFilesystem filesystem, com.google.common.collect.ImmutableList<Path> stringFiles, Path rDotTxtFile, java.util.function.Function<String,Path> pathBuilder)
stringFiles
- Set containing paths to strings.xml files matching GetStringsFilesStep.STRINGS_FILE_PATH
rDotTxtFile
- Path to the R.txt file generated by aapt.pathBuilder
- Builds a path to store a .fbstr file at.public StepExecutionResult execute(ExecutionContext context) throws IOException
execute
in interface Step
IOException
public static void buildResourceNameToIdMap(ProjectFilesystem filesystem, Path pathToRDotTxtFile, Map<String,Integer> stringResourceNameToIdMap, Map<String,Integer> pluralsResourceNameToIdMap, Map<String,Integer> arrayResourceNameToIdMap) throws IOException
string
, plurals
and array
, and builds a map of resource names to their corresponding ids.IOException
public String getShortName()
getShortName
in interface Step
public String getDescription(ExecutionContext context)
getDescription
in interface Step