Toolserver:TSMessages.php

TSMessages.phpALPHA is a script to get messages from translatewiki.net or local i18n files.

class TSLanguageSelector
TSLanguageSelector([string $default [, string $varname [, string $cookiePrefix [, string $cookiePath [, string $cookieDomain ]]]]])
 * $default is the default language of your script. Default:"en"
 * $varname is the name of the GET key which bear the user selected language. Default:"lang"
 * $cookiePrefix is the prefix of the cookie name. The cookie name is conglomerated with $cookiePrefix and $varname. Default:""
 * $cookiePath is the path which is added to the cookie. Default:NULL
 * $cookieDomain is the domain which is added to the cookie. Default:NULL

return: Language Object. This class should be called before any output because it sets the language cookie.

getSelectorFormHTML
getSelectorFormHTML(object $messages[, boolean $auto_submit[, string $name ]])
 * $messages is the object from createDefaultMessageObject↓
 * $auto_submit defines whether or not the language field is submitted automatically when the user chooses a language. It works only with Javascript enabled, otherwise the user sees an "ok" button. Default: true
 * $name is the name and the id of the form field. Default: "languageselector"

Return: HTML form to select a language.

getSelectorListHTML
getSelectorListHTML(object $messages)
 * $messages is the object from createDefaultMessageObject↓

Return: HTML list of languages to choose from, like zhis: de | en | fr | gsw |...

class TSMessagesFactory
TSMessagesFactory( [string $file [, resource $connection [, string $prefix [, boolean $multilang [, string $memcachedserver [, int $memcachedport ]]]]]] )
 * $file: the path to the folder if you have messages as i18n.php files. Default: NULL
 * $connection: mysql resource. If you don't have already a connection you can set it to NULL, then the script parse your .my.cnf and self-connect. If you need the connection furthermore in your tool you can get it with db_connect ↓. Default: NULL
 * $prefix: If your message keys starts all with the same prefix, you can set it there, then you can deliver the keys later without the prefix. Please beware that this prefix is used for all message keys! Default: NULL
 * $multilang: set it to false if you have for every language a own file. if you have all messages in one file set it to true. Default: true
 * $memcachedserver: memcached server address. Default: localhost
 * $memcachedport: memcached server port. Default: 11211

Return: Object to get the messages.

db_connect
db_connect

This is a static function!

Return: mysql connection resource.

memcached_connect
memcached_connect

This is a static function!

Return: memcached object.

createDefaultMessageObject
createDefaultMessageObject( mixed $tool [, mixed $lang]) for the order of the array see [[Toolserver:
 * $tool string or array with the needed tools. There are different variants:
 * 1) getAvailableLanguages|getAvailableLanguages]]
 * $lang: string with the shortcut of the needed language or TSLanguageSelector↑ object. If a message is not available in the required language it fall back to English (en).

Return: TSMessages object.

class TSMessages
returned by createDefaultMessageObject↑

getMessage
getMessage(string $key [,array $replacers [, boolean $parse ]]) Parsed will be:
 * $key: key of the message you request
 * $replacers: If the message contains placeholders like $1, $2 etc you can add a array with the content to replace them: default: array
 * $parse: if you don't like to parse the text, set it to false. default: true
 * $1, $2, $3 etc. replaced with declared text
 * --> dependent on $1 "there is a message" or "there are $1 messages"
 * Bold --> Bold
 * Italic --> Italic

Return: message as string

getMessageEscaped
getMessageEscaped (string $key [,array $replacers [, boolean $parse ]]) same output like getMessage↑ but escaped with htmlspecialchars.

getKeys
getKeys get all keys which are loaded in this object.

Return: array with loaded keys.

getAvailableLanguages
getAvailableLanguages return a array with all languages your tool is translated. for that it takes the first tool who is listed at createDefaultMessageObject $tool and checks it, because of that the first element in the array should be the tool who is translated at least. For files the whole directory is checked.

form:

ToDo

 * Get language from Browser header $_SERVER["HTTP_ACCEPT_LANGUAGE"] - Done by Luxo
 * create message database on the toolserver
 * support for memcached - there are two php modules, memcached or memcache
 * testing testing testing

Category:Documentation