Package resources

Class Language.LocalizedFileName

  • Enclosing class:
    Language

    public static final class Language.LocalizedFileName
    extends java.lang.Object
    Splits a file name into tokens to extract locale information. Some kinds of file names, such as string tables, may include a locale as part of the file name. This class splits such file names into three parts: a base name, an extension, and a locale description. A typical example:
     occupations_ll_CC.properties
     \_________/ \___/ \________/
      base name  locale extension
     

    The file name is broken into parts as follows:

    1. The extension consists of all text after the first period (.), or null if there is no period in the name.
    2. The base name consists of all text from the start of the string up to the first underscore (_) if any. If there is no underscore, then it continues up until the first period, if any, and otherwise to the end of the string.
    3. The locale description consists of the text after the first underscore and up to the first period (.), if any. If there is no underscore, then the locale description is null. if there is no period, then the description continues to the end of the string. If there is no underscore in the file name, then the locale description is null. Moreover, the locale is checked to determine if it is valid, as described below. If the locale is not valid, then the locale description will be null and the part that would have been the locale description, including the initial underscore, will be included in the base name as if there were no underscore in the name.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.lang.String baseName
      The base name that was parsed out of the file name.
      java.lang.String extension
      The file extension of the file (such as .properties), or null if there is no file extension.
      java.lang.String localeDescription
      The locale description that was parsed out of the file name, or null if there was no locale description.
    • Constructor Summary

      Constructors 
      Constructor Description
      LocalizedFileName​(java.io.File file)
      Creates a localized file name from the name of the given file.
      LocalizedFileName​(java.lang.String fileName)
      Creates a localized file name from a file name string.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getDefaultFileName()
      Returns the file name for the default translation file.
      java.lang.String getFileNameFor​(java.util.Locale loc)
      Returns the file name for a localized file with the same base name and extension but the specified locale.
      java.util.Locale getLocale()
      Returns a locale matching the locale description.
      Language.LocalizedFileName getParent()
      Returns the localized file name for the parent locale, or null if this file represents a default translation.
      java.lang.String toString()
      Returns a string that describes the parts of the localized file name.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • baseName

        public final java.lang.String baseName
        The base name that was parsed out of the file name. This may be an empty string, but it will not be null.
      • localeDescription

        public final java.lang.String localeDescription
        The locale description that was parsed out of the file name, or null if there was no locale description. A null locale description indicates that the file is either not part of a family of localized files, or that it represents the default translation. If it is the default translation and other translations are available, other files in the same folder should have the same base name and extension.
      • extension

        public final java.lang.String extension
        The file extension of the file (such as .properties), or null if there is no file extension.
    • Constructor Detail

      • LocalizedFileName

        public LocalizedFileName​(java.io.File file)
        Creates a localized file name from the name of the given file.
        Parameters:
        file - the file name to tokenize
        Throws:
        java.lang.NullPointerException - if the file is null
      • LocalizedFileName

        public LocalizedFileName​(java.lang.String fileName)
        Creates a localized file name from a file name string.
        Parameters:
        fileName - the file name to tokenize
        Throws:
        java.lang.NullPointerException - if the file is null
    • Method Detail

      • getLocale

        public java.util.Locale getLocale()
        Returns a locale matching the locale description. Returns null if the locale description is null.
        Returns:
        the locale for the locale description, or null
        See Also:
        Language.parseLocaleDescription(java.lang.String)
      • getDefaultFileName

        public java.lang.String getDefaultFileName()
        Returns the file name for the default translation file. For example, if the original file was fruit_fr.properties, this would return fruit.properties.
        Returns:
        the file name representing the default translation in a group of localized files
      • getFileNameFor

        public java.lang.String getFileNameFor​(java.util.Locale loc)
        Returns the file name for a localized file with the same base name and extension but the specified locale. If the locale is null, then this returns the default file name.
        Parameters:
        loc - the locale to create a file name for
        Returns:
        the file name for the specified locale
        See Also:
        getDefaultFileName()
      • getParent

        public Language.LocalizedFileName getParent()
        Returns the localized file name for the parent locale, or null if this file represents a default translation. For example, the parent of file_en_CA.ext is file_en.ext; The parent of file_en.ext is file.ext, and the parent of that file is null.
        Returns:
        the next fallback translation for the file, or null
      • toString

        public java.lang.String toString()
        Returns a string that describes the parts of the localized file name. This is only intended for use in debugging purposes.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a description of the file name tokens