lib/ezi18n/classes/eztstranslator.php
File containing the eZTSTranslator class.
- Copyright
- Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.
- License
-
eZ Business Use License Agreement Version 2.0
- Package
- lib
- Subpackage
- i18n
- Version
- 4.6.0
Package: lib\i18nProvides internationalization using XML (.ts) files
- Parent(s)
- \eZTranslatorHandler
- Copyright
- Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.
- Version
- 4.6.0
Constants


EXPIRY_KEY
= 'ts-translation-cache'
Translation expiry key used by eZExpiryHandler to manage translation caches
Properties
Methods



eZTSTranslator(
string $locale, string $filename
=
null, bool $useCache
=
true
)
:
void
Constructs the translator and loads the translation file $file if it is set and exists.
Parameters
Name |
Type |
Description |
$locale |
string |
|
$filename |
string |
|
$useCache |
bool |
|



expireCache(
int $timestamp
=
false, string $locale
=
null
)
:
void
staticExpires the translation cache
Parameters
Name |
Type |
Description |
$timestamp |
int |
An optional timestamp cache should be exired from. Current timestamp used by default |
$locale |
string |
Optional translation's locale to expire specifically. Expires global ts cache by default.
|



fetchList(
$localeList
=
array()
)
:
\array(
staticFetches the list of available translations, as an eZTSTranslator for each translation.
Parameters
Name |
Type |
Description |
$localeList |
|
|
Returns
Type |
Description |
\array( |
eZTSTranslator ) list of eZTranslator objects representing available translations |



findKey(
string $key
)
:
array | false
Returns the message that matches a translation md5 key
Parameters
Name |
Type |
Description |
$key |
string |
|
Returns
Type |
Description |
array | false |
The message, as an array, or false if not found |



findMessage(
string $context, string $source, string $comment
=
null
)
:
array | false
Returns the message that matches a context / source / comment
Parameters
Name |
Type |
Description |
$context |
string |
|
$source |
string |
|
$comment |
string |
|
Returns
Type |
Description |
array | false |
The message, as an array, or false if not found |



handleMessageNode(
string $contextName, \DOMNode $message
)
:
void
Handles a translation message DOM node
Parameters
Name |
Type |
Description |
$contextName |
string |
|
$message |
\DOMNode |
|



hasInitializedContext(
string $context
)
:
bool
Checks if a context has been initialized (cached)
Parameters
Name |
Type |
Description |
$context |
string |
|
Returns
Type |
Description |
bool |
True if the context was initialized before, false if it wasn't |



initialize(
string $context, string $locale, string $filename, bool $useCache
=
true
)
:
\eZTSTranslator
staticInitialize the ts translator and context if this is not already done
Parameters
Name |
Type |
Description |
$context |
string |
|
$locale |
string |
|
$filename |
string |
|
$useCache |
bool |
|
Returns



insert(
string $context, string $source, string $translation, string $comment
=
null
)
:
string
Inserts the translation $translation for the context $context and source $source as a translation message.
Returns the key for the message. If $comment is non-null it will be included in the message.
If the translation message exists no new message is created and the existing key is returned.
Parameters
Name |
Type |
Description |
$context |
string |
|
$source |
string |
|
$translation |
string |
|
$comment |
string |
|
Returns
Type |
Description |
string |
The translation (md5) key |



keyTranslate(
string $key
)
:
string | false
Returns the translation for a translation md5 key
Parameters
Name |
Type |
Description |
$key |
string |
|
Returns
Type |
Description |
string | false |
|



load(
string $requestedContext
)
:
bool
Tries to load the context $requestedContext for the translation and returns true if was successful.
Parameters
Name |
Type |
Description |
$requestedContext |
string |
|
Returns
Type |
Description |
bool |
True if load was successful, false otherwise |



loadTranslationFile(
string $locale, string $filename, string $requestedContext
)
:
bool
Loads a translation file
Will load from cache if possible, or generate cache if needed
Also checks for translation files expiry based on mtime if RegionalSettings.TranslationCheckMTime is enabled
Parameters
Name |
Type |
Description |
$locale |
string |
|
$filename |
string |
|
$requestedContext |
string |
|
Returns
Type |
Description |
bool |
The operation status, true or false |
Details
- Access
- private



remove(
string $context, string $source, string $message
=
null
)
:
bool
Removes the translation message with context $context and source $source.
If you have the translation key use removeKey() instead.
Parameters
Name |
Type |
Description |
$context |
string |
|
$source |
string |
|
$message |
string |
|
Returns
Type |
Description |
bool |
true if the message was removed, false otherwise |



removeKey(
string $key
)
:
bool
Removes the translation message with the key $key.
Parameters
Name |
Type |
Description |
$key |
string |
The translation md5 key |
Returns
Type |
Description |
bool |
true if the message was removed, false otherwise |



translate(
string $context, string $source, string $comment
=
null
)
:
string | false
Translates a context + source + comment
Parameters
Name |
Type |
Description |
$context |
string |
|
$source |
string |
|
$comment |
string |
|
Returns
Type |
Description |
string | false |
|



validateDOMTree(
\DOMDocument $tree
)
:
bool
staticValidates the DOM tree $tree and returns true if it is correct
Parameters
Returns
Type |
Description |
bool |
True if the DOMDocument is valid, false otherwise |