OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | Static Public Member Functions | List of all members
OpenXcom::Language Class Reference

Contains strings used throughout the game for localization. More...

#include <Language.h>

Public Member Functions

 Language ()
 Creates a blank language. More...
 
 ~Language ()
 Cleans up the language.
 
void load (const std::string &filename, ExtraStrings *extras)
 Loads the language from a YAML file. More...
 
std::string getId () const
 Gets the language's ID. More...
 
std::wstring getName () const
 Gets the language's name. More...
 
void toHtml (const std::string &filename) const
 Outputs the language to a HTML file. More...
 
const LocalizedTextgetString (const std::string &id) const
 Get a localized text. More...
 
LocalizedText getString (const std::string &id, unsigned n) const
 Get a quantity-depended localized text. More...
 
const LocalizedTextgetString (const std::string &id, SoldierGender gender) const
 Get a gender-depended localized text. More...
 
TextDirection getTextDirection () const
 Gets the direction of text in this language. More...
 
TextWrapping getTextWrapping () const
 Gets the wrapping of text in this language. More...
 

Static Public Member Functions

static std::string wstrToUtf8 (const std::wstring &src)
 Converts a wide-string to UTF-8. More...
 
static std::string wstrToCp (const std::wstring &src)
 Converts a wide-string to local-codepage string. More...
 
static std::string wstrToFs (const std::wstring &src)
 Converts a wide-string to filesystem string. More...
 
static std::wstring utf8ToWstr (const std::string &src)
 Converts a UTF-8 string to wide-string. More...
 
static std::wstring cpToWstr (const std::string &src)
 Converts a local-codepage string to wide-string. More...
 
static std::wstring fsToWstr (const std::string &src)
 Converts a filesystem string to wide-string. More...
 
static void replace (std::string &str, const std::string &find, const std::string &replace)
 Replaces a substring. More...
 
static void replace (std::wstring &str, const std::wstring &find, const std::wstring &replace)
 Replaces a substring. More...
 
static void getList (std::vector< std::string > &files, std::vector< std::wstring > &names)
 Gets list of languages in the data directory. More...
 

Detailed Description

Contains strings used throughout the game for localization.

Languages are just a set of strings identified by an ID string.

Constructor & Destructor Documentation

OpenXcom::Language::Language ( )

Creates a blank language.

Initializes an empty language file.

Member Function Documentation

std::wstring OpenXcom::Language::cpToWstr ( const std::string &  src)
static

Converts a local-codepage string to wide-string.

Takes an 8-bit string encoded in the current system codepage and converts it to a wide-character string.

Parameters
srcCodepage string.
Returns
Wide-character string.
std::wstring OpenXcom::Language::fsToWstr ( const std::string &  src)
static

Converts a filesystem string to wide-string.

Takes an 8-bit string with the filesystem encoding and converts it to a wide-character string.

Parameters
srcFilesystem string.
Returns
Wide-character string.
std::string OpenXcom::Language::getId ( ) const

Gets the language's ID.

Returns the language's locale.

Returns
IANA language tag.
void OpenXcom::Language::getList ( std::vector< std::string > &  files,
std::vector< std::wstring > &  names 
)
static

Gets list of languages in the data directory.

Gets all the languages found in the Data folder and returns their properties.

Parameters
filesList of language filenames.
namesList of language human-readable names.
std::wstring OpenXcom::Language::getName ( ) const

Gets the language's name.

Returns the language's name in its native language.

Returns
Language name.
const LocalizedText & OpenXcom::Language::getString ( const std::string &  id) const

Get a localized text.

Returns the localized text with the specified ID.

If it's not found, just returns the ID.

Parameters
idID of the string.
Returns
String with the requested ID.
LocalizedText OpenXcom::Language::getString ( const std::string &  id,
unsigned  n 
) const

Get a quantity-depended localized text.

Returns the localized text with the specified ID, in the proper form for n.

The substitution of n has already happened in the returned LocalizedText. If it's not found, just returns the ID.

Parameters
idID of the string.
nNumber to use to decide the proper form.
Returns
String with the requested ID.
const LocalizedText & OpenXcom::Language::getString ( const std::string &  id,
SoldierGender  gender 
) const

Get a gender-depended localized text.

Returns the localized text with the specified ID, in the proper form for the gender.

If it's not found, just returns the ID.

Parameters
idID of the string.
genderCurrent soldier gender.
Returns
String with the requested ID.
TextDirection OpenXcom::Language::getTextDirection ( ) const

Gets the direction of text in this language.

Returns the direction to use for rendering text in this language.

Returns
Text direction.
TextWrapping OpenXcom::Language::getTextWrapping ( ) const

Gets the wrapping of text in this language.

Returns the wrapping rules to use for rendering text in this language.

Returns
Text wrapping.
void OpenXcom::Language::load ( const std::string &  filename,
ExtraStrings extras 
)

Loads the language from a YAML file.

Loads a language file in Ruby-on-Rails YAML format.

Not that this has anything to do with Ruby, but since it's a widely-supported format and we already have YAML, it was convenient.

Parameters
filenameFilename of the YAML file.
extrasPointer to extra strings from ruleset.
void OpenXcom::Language::replace ( std::string &  str,
const std::string &  find,
const std::string &  replace 
)
static

Replaces a substring.

Replaces every instance of a substring.

Parameters
strThe string to modify.
findThe substring to find.
replaceThe substring to replace it with.
void OpenXcom::Language::replace ( std::wstring &  str,
const std::wstring &  find,
const std::wstring &  replace 
)
static

Replaces a substring.

Replaces every instance of a substring.

Parameters
strThe string to modify.
findThe substring to find.
replaceThe substring to replace it with.
void OpenXcom::Language::toHtml ( const std::string &  filename) const

Outputs the language to a HTML file.

Outputs all the language IDs and strings to an HTML table.

Parameters
filenameHTML file.
std::wstring OpenXcom::Language::utf8ToWstr ( const std::string &  src)
static

Converts a UTF-8 string to wide-string.

Takes an 8-bit string encoded in UTF-8 and converts it to a wide-character string.

Note
Adapted from http://stackoverflow.com/questions/148403/utf8-to-from-wide-char-conversion-in-stl
Parameters
srcUTF-8 string.
Returns
Wide-character string.
std::string OpenXcom::Language::wstrToCp ( const std::wstring &  src)
static

Converts a wide-string to local-codepage string.

Takes a wide-character string and converts it to an 8-bit string encoded in the current system codepage.

Parameters
srcWide-character string.
Returns
Codepage string.
std::string OpenXcom::Language::wstrToFs ( const std::wstring &  src)
static

Converts a wide-string to filesystem string.

Takes a wide-character string and converts it to an 8-bit string with the filesystem encoding.

Parameters
srcWide-character string.
Returns
Filesystem string.
std::string OpenXcom::Language::wstrToUtf8 ( const std::wstring &  src)
static

Converts a wide-string to UTF-8.

Takes a wide-character string and converts it to a 8-bit string encoded in UTF-8.

Note
Adapted from http://stackoverflow.com/questions/148403/utf8-to-from-wide-char-conversion-in-stl
Parameters
srcWide-character string.
Returns
UTF-8 string.

The documentation for this class was generated from the following files: