Package resources
Class Language.LocalizedFileName
- java.lang.Object
-
- resources.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:
- The extension consists of all text after the first period (.), or
null
if there is no period in the name. - 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.
- 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 isnull
. 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 benull
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
), ornull
if there is no file extension.java.lang.String
localeDescription
The locale description that was parsed out of the file name, ornull
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, ornull
if this file represents a default translation.java.lang.String
toString()
Returns a string that describes the parts of the localized file name.
-
-
-
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 benull
.
-
localeDescription
public final java.lang.String localeDescription
The locale description that was parsed out of the file name, ornull
if there was no locale description. Anull
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
), ornull
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 isnull
-
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 isnull
-
-
Method Detail
-
getLocale
public java.util.Locale getLocale()
Returns a locale matching the locale description. Returnsnull
if the locale description isnull
.- 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 wasfruit_fr.properties
, this would returnfruit.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 isnull
, 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, ornull
if this file represents a default translation. For example, the parent offile_en_CA.ext
isfile_en.ext
; The parent offile_en.ext
isfile.ext
, and the parent of that file isnull
.- 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 classjava.lang.Object
- Returns:
- a description of the file name tokens
-
-