Gets an instance of the atkLanguage class
Using this function will ensure that only 1 instance ever exists (singleton).
API Tags:
| Return: | Instance of the atkLanguage class |
| Access: | public |
static String getLanguage(
)
|
|
Get the current language, either from url, or if that's not present, from what the user has set.
API Tags:
| Return: | current language. |
| Access: | public |
static String getLanguageFromHeaders(
)
|
|
Get the primary languagecode that the user has set in his/her browser
API Tags:
| Return: | The languagecode |
| Access: | public |
static Array getSupportedLanguages(
)
|
|
Get the languages supported by the application
API Tags:
| Return: | An array with the languages supported by the application. |
| Access: | public |
static unknown getUserLanguage(
)
|
|
Get the selected language of the current user if he/she set one, otherwise we try to get it from the browser settings and if even THAT fails, we return the default language.
API Tags:
static void setLanguage(
String
$lng
)
|
|
Change the current language.
Note that his only remains set for the current request, it's not session based.
Parameters:
|
String |
$lng: |
The language to set |
API Tags:
static void setSupportedLanguages(
$languages
)
|
|
Explicitly sets the supported languages.
Parameters:
|
array |
$languages: |
supported languages |
API Tags:
static String text(
mixed
$string, String
$module, [String
$node = ""], [String
$lng = ""], [String
$firstfallback = ""], [bool
$nodefaulttext = false], [bool
$modulefallback = false]
)
|
|
Text function, retrieves a translation for a certain string.
Parameters:
|
mixed |
$string: |
string or array of strings containing the name(s) of the string to return when an array of strings is passed, the second will be the fallback if the first one isn't found, and so forth |
|
String |
$module: |
module in which the language file should be looked for, defaults to core module with fallback to ATK |
|
String |
$node: |
the node to which the string belongs |
|
String |
$lng: |
ISO 639-1 language code, defaults to config variable |
|
String |
$firstfallback: |
the first module to check as part of the fallback |
|
bool |
$nodefaulttext: |
if true, then it doesn't returns false when it can't find a translation |
|
bool |
$modulefallback: |
Wether or not to use all the modules of the application in the fallback, when looking for strings |
API Tags:
| Return: | the string from the languagefile |
| Access: | public |
atkLanguage __construct(
)
|
|
Default Constructor
API Tags:
void addFallbackModule(
String
$module
)
|
|
Add a module that servers as a fallback for language strings.
Parameters:
|
String |
$module: |
Name of the module to add. |
API Tags:
void addOverrideModule(
String
$module
)
|
|
Add a module that serves as an override for language strings.
Parameters:
|
String |
$module: |
Name of the module to add. |
API Tags:
string defaultText(
string
$string
)
|
|
A function to change the original "$something_text" string to
"Something text" This is only used when we really can't find the "$something_text" anywhere
Parameters:
|
string |
$string: |
the name of the string to return |
API Tags:
| Return: | the changed string |
| Access: | public |
String getLanguageDirForModule(
String
$module
)
|
|
Method for getting the relative path to the languagedirectory of a module.
Supports 2 special modules:
- atk (returns the path of the atk languagedir)
- langoverrides (returns the path of the languageoverrides dir)
Special method in that it can run both in static and non-static mode.
Parameters:
|
String |
$module: |
The module to get the languagedir for |
API Tags:
| Return: | The relative path to the languagedir |
| Access: | public |
void setText(
string
$code, string
$text, string
$lng
)
|
|
Set a custom language string
Parameters:
|
string |
$code: |
The code of the custom string |
|
string |
$text: |
Text |
|
string |
$lng: |
Language |
API Tags:
array _getFallbackModules(
bool
$modulefallback
)
|
|
Calculate the list of fallbackmodules.
Parameters:
|
bool |
$modulefallback: |
Wether or not to use all the modules of the application in the fallback, when looking for strings |
API Tags:
| Return: | Array of fallback modules |
| Access: | protected |
array _getModules(
String
$module, [String
$firstfallback = ""], [Boolean
$modulefallback = false]
)
|
|
Determine the list of modules we need to go through to check language strings. Overrides have precedence, then the passed module is considered, finally if no string is found the fallbacks are checked.
Parameters:
|
String |
$module: |
manually passed module |
|
String |
$firstfallback: |
an additional module in which the translation will be searched first, if not found in the module itself. |
|
Boolean |
$modulefallback: |
If true, *all* modules are checked. |
API Tags:
| Return: | List of modules to use to find the translations |
| Access: | protected |
string _getString(
string
$key, string
$module, string
$lng, [string
$node = ""], [bool
$nodefaulttext = false], [string
$firstfallback = ""], [bool
$modulefallback = false]
)
|
|
This function takes care of the fallbacks when retrieving a string ids.
It is as following: First we check for a string specific to both the module and the node (module_node_key). If that isn't found we check for a node specific string (node_key). And if all that fails we look for a general string in the module.
Parameters:
|
string |
$key: |
the name of the string to return |
|
string |
$module: |
module in which the language file should be looked for, defaults to core module with fallback to ATK |
|
string |
$lng: |
ISO 639-1 language code, defaults to config variable |
|
string |
$node: |
the node to which the string belongs |
|
bool |
$nodefaulttext: |
wether or not to pass a default text back |
|
string |
$firstfallback: |
the first module to check as part of the fallback |
|
bool |
$modulefallback: |
Wether or not to use all the modules of the application in the fallback, when looking for strings |
API Tags:
| Return: | the name with which to call the string we want from the languagefile |
| Access: | protected |
var _getStringFromFile(
string
$key, string
$module, string
$lng
)
|
|
Gets the string from the languagefile or, if we failed, returns ""
Parameters:
|
string |
$key: |
the name which was given when the text function was called |
|
string |
$module: |
the name of the module to which the text function belongs |
|
string |
$lng: |
the current language |
API Tags:
| Return: | the true name by which the txt is called or "" if we can't find any entry |
| Access: | protected |
bool _includeLanguage(
string
$module, string
$lng
)
|
|
Checks wether the language is set or not
If set, it does nothing and return true otherwise it sets it
Parameters:
|
string |
$module: |
the module to import the language file from |
|
string |
$lng: |
language of file to import |
API Tags:
| Return: | true if everything went okay |
| Access: | protected |