-
Notifications
You must be signed in to change notification settings - Fork 34
functions_essentials_translation
Initializes the translation essential.
Definition: public function translation_init()
Returns: void
INTERNAL Includes the translation files
Adds a custom translation function. Use this to add your own placeholder replacer function. Should accept a single argument which contains the string and return the ready string.
function my_trans($text)
{
return str_replace('{username}',"It's Me, Mario!",$text);
}
translation_add_function('my_trans'); Definition: public function translation_add_function($func)
Returns: void
Parameters:
-
string $funcName of translation function
INTERNAL preg_replace_callback handler
INTERNAL Used to add some new/unknown strings to the translation system
Ensures that a specific content remains untranslated. This may be useful when automatic translation would match one of you texts. Also very good to prevent user-input from beeing translated!
Definition: public function noTranslate($content)
Returns: string Returns the string containing attributes to ensure it will not be translated (NT)
Parameters:
-
string $contentContent to remain untranslated
Detects the users supposed language. Uses Localization::detectCulture to detect the users language.
Definition: public function detect_language()
Returns: string ISO2 code of detected language
Sets the language and return the current one.
Definition: public function translation_set_language($code_or_ci)
Returns: string the previously set language
Parameters:
-
mixed $code_or_ciCulture code or CultureInfo
Like getString(), but for a specific language.
Definition: public function getStringLang($lang, $constant, $arreplace=null, $unbuffered=false)
Returns: string The translated string
Parameters:
-
string $langLanguage to get string for -
string $constantString to translate -
array $arreplaceArray with replacement data -
bool $unbufferedIf true skips buffering
SHORTCUT for getString($constant, $arreplace, $unbuffered, $encoding)
SHORTCUT for getStringOrig($constant, $arreplace, $unbuffered, $encoding)
Returns a localized string from the current user's language. Replaces all placeholders in string from arreplace i.e. TXT_TEST => "this is a {tt}" with arreplace = aray("{tt}" => "test") => returns "this is a test" Buffers all strings on first access of this function.
Definition: public function getStringOrig($constant, $arreplace=null, $unbuffered=false, $encoding=null)
Returns: string Translated string
Parameters:
-
string $constantText constant. i.e. TXT_... -
array $arreplaceReplacement array -
bool $unbufferedReload from session instead of from cache buffer of current script -
string $encodingE.g. cp1252. Default "null" => UTF-8 will be returned
SHORTCUT for getString but ensuring that it is escaped for use in JS
INTERNAL Replaces variables in strings
Returns a list of all languages that have enough translated strings to be usable.
Definition: public function getAvailableLanguages($min_percent_translated=false)
Returns: array Array of language codes
Parameters:
-
int $min_percent_translatedSpecifies how many percent must be translated for a language to be 'available'
Checks if there are translations for the given culture.
Definition: public function checkForExistingLanguage($cultureCode)
Returns: string|bool The given culture code or false
Parameters:
-
string $cultureCodeCulture code to check for
Returns a list of all known constants.
Definition: public function translation_known_constants()
Returns: array List of all constants
INTERNAL Skips buffering for the current call
Checks if a string constant exists. You can use this to test if a string is a translation constant too.
Definition: public function translation_string_exists($constant)
Returns: bool true or false
Parameters:
-
string $constantConstant to check for existance
Checks if the given text is a valid constant according to the translation regex pattern.
Definition: public function translation_is_valid_constant($constant)
Returns: bool
Parameters:
-
string $constantText to be tested
INTERNAL Ensures that a string will not be translated
'Registers' a string in the translation system with a default value. This is used in ScavixWDF when components require user-interaction without forcing the implementor to create 100ths of strings as the first he must do.
Definition: public function default_string($constant, $text)
Returns: string The $constant value
Parameters:
-
string $constantConstant name -
string $textThe defauilt text
SHORTCUT for default_string($constant, $text)
SHORTCUT for clear_trans_data() followed by add_trans_data($name,$data)
Adds data to the automatic translation system. Use this to add a bunch of data to the translation system. Sample is best to understand:
function SomeControllersInitMethod()
{
$str_const = default_string('TXT_TEST','Hello {user.name}! I want to tell you all about {product.name}. Is {user.email} your email address?');
add_trans_data('user',UserModel::Make()->eq('id',1)->current());
add_trans_data('product',ProductModel::Make()->eq('id',1)->current());
$this->content($str_content);
} Definition: public function add_trans_data($name, $data, $depth)
Returns: void
Parameters:
-
string $nameName of the data -
mixed $dataThe data do add. Can be int, bool string, object, array, ... -
int $depthCurrent recursion depth. Ignore this, it's internal only.
Clears the translation data store.
Definition: public function clear_trans_data()
Returns: void