| core_text

# Class: Bs_LanguageHandler Source Location: /core/text/Bs_LanguageHandler.class.php
### Class Overview
    Bs_Object
       |
       --Bs_LanguageHandler
This class provides methods to work with different languages. #### Author(s): Andrej Arn <at blueshoes dot org> #### Version: 4.3.$Revision: 1.3 $ $Date: 2003/10/29 17:48:42 $ #### Copyright: blueshoes.org | ### Variables $_APP $_IniHandler | ### Methods Bs_LanguageHandler determineLanguage readLanguage
### Inherited Variables | ### Inherited Methods #### Class: Bs_Object Bs_Object::Bs_Object() Bs_Object::getErrors() Basic error handling: Get *all* errors as string array from the global Bs_Error-error stack. Bs_Object::getLastError() Basic error handling: Get last error string from the global Bs_Error-error stack. Bs_Object::getLastErrors() Basic error handling: Get last errors string array from the global Bs_Error-error stack sinc last call of getLastErrors(). Bs_Object::persist() Persists this object by serializing it and saving it to a file with unique name. Bs_Object::setError() Basic error handling: Push an error string on the global Bs_Error-error stack. Bs_Object::toHtml() Dumps the content of this object to a string using PHP's var_dump(). Bs_Object::toString() Dumps the content of this object to a string using PHP's var_dump(). Bs_Object::unpersist() Fetches an object that was persisted with persist()
### Class Details [line 41] This class provides methods to work with different languages. it uses files (like ini files, text files) for each language. example usage: put the following content into the file '/some/dir/Html/Form/validationErrors.en-uk.txt': [default] this is a comment line greeting = hello world foo = another language definition now add this code to your php script: require_once($APP['path']['core'] . 'util/Bs_LanguageHandler.class.php'); $Bs_LanguageHandler =& new Bs_LanguageHandler(); $t = &$Bs_LanguageHandler->determineLanguage('/some/dir/Html/Form/validationErrors', 'en-uk'); if (is_null($t)) echo 'unknown error'; //yuck. list($lang, $path) = $t; $languageHash = &$Bs_LanguageHandler->readLanguage($path); echo $languageHash['default']['greeting']; now you have "hello world" on your screen. also see determineLanguage() to find out how to build your language files. dependencies: Bs_IniHandler #### Tags:
pattern: | singleton: (pseudostatic)
todo: | currently only reads the languages, should be able to write also. (implement in Bs_IniHandler)
access: | public
version: | 4.3.$Revision: 1.3 $ $Date: 2003/10/29 17:48:42 $
copyright: | blueshoes.org
author: | Andrej Arn <at blueshoes dot org>
[ Top ] ### Class Variables #### $_APP = [line 48] reference
Type: | array
[ Top ] #### $_IniHandler = [line 54] instance of class Bs_IniHandler
Type: | object
[ Top ] ### Class Methods ### constructor Bs_LanguageHandler [line 60]
`Bs_LanguageHandler Bs_LanguageHandler( )`
Constructor [ Top ] ### method determineLanguage [line 104]
`array determineLanguage( string $path, [string $lang = NULL])`
get the language that fits our needs. if we are not absolutely sure if our language exist (and we are not), then we need to find out which one we can use. param $path: absolute path to the directory where the language files are. also include the unique base name of the lang files. example: you have these files /some/dir/errors.en-us.txt /some/dir/errors.en.txt /some/dir/errors.de.txt /some/dir/errors.fr.txt so your call would look like determineLanguage('/some/dir/errors', 'en-uk'); which would load '/some/dir/errors.en.txt' (because en-uk does not exist). in this example the base name is "errors". the files have to end with '.txt'. #### Tags:
return: | (a vector with 2 elements. 1 = language, 2 = absolute path to language file.)
throws: | NULL
access: | public
#### Parameters:
string | $path | (see above.)
string | $lang | (if not set then the default lang (from $APP['usedLanguages']) will be used. if this fails, 'en' will be used.)
[ Top ] ### method readLanguage [line 74]
`array &readLanguage( string $path)`
reads the given language file. #### Tags:
return: | a hash with the key/text values.
throws: | NULL
access: | public
#### Parameters:
string | $path | the fullpath to the language file.
[ Top ] Documentation generated on Mon, 29 Dec 2003 21:11:40 +0100 by phpDocumentor 1.2.3