Class CompileStringsStep

  • All Implemented Interfaces:
    Step

    public class CompileStringsStep
    extends Object
    implements Step
    This 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:

    1. a string
    2. a map of plurals
    3. a list of strings
    and dumps this map into the output file. See StringResources for the file format.
    • Constructor Detail

      • CompileStringsStep

        public 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.
        Parameters:
        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.