Languages extends AppModel
Language management. Maintains all languages installed on the system and allows new languages to be installed.
All language codes are in ISO 639-1 ISO 3166-1 alpha-2 concatenated format (i.e. "en_us")
Table of Contents
Methods
| __construct() | Initialize Languages |
| add() | Installs the given language file for the given company, if it exists |
| delete() | Uninstalls the given language |
| get() | Fetches an installed language available to the given company |
| getAll() | Fetches all languages installed at the given company |
| getAllUninstallable() | Retrieves a list of all languages that cannot be uninstalled for this company |
| getAvailable() | Get all available languages on the file system |
| validateCodeExists() | Validates whether or not the $code and $company_id combination already exists |
| validateDefaultLang() | Validates whether or not the $code and $company_id combination are the default language, or 'en_us' |
| getDefaultLang() | Fetches the default language code for this company |
| getNameFromFile() | Fetches the name of the language from the file system if the language exists and contains the language name file |
Methods
__construct()
Initialize Languages
public
__construct() : mixed
add()
Installs the given language file for the given company, if it exists
public
add(int $company_id, string $code) : mixed
Parameters
- $company_id : int
-
The ID of the company under which the language should be installed
- $code : string
-
The language to install in ISO 639-1 ISO 3166-1 alpha-2 concatenated format (e.g. "en_us")
delete()
Uninstalls the given language
public
delete(int $company_id, string $code) : mixed
Parameters
- $company_id : int
-
The ID of the company to uninstall the given language from
- $code : string
-
The language code under the given company to uninstall
get()
Fetches an installed language available to the given company
public
get(int $company_id, string $code) : mixed
Parameters
- $company_id : int
-
The ID of the company to fetch installed languages under.
- $code : string
-
The language installed in ISO 639-1 ISO 3166-1 alpha-2 concatenated format (e.g. "en_us")
getAll()
Fetches all languages installed at the given company
public
getAll(int $company_id) : array<string|int, mixed>
Parameters
- $company_id : int
-
The ID of the company to fetch installed languages under.
Return values
array<string|int, mixed> —An array of stdClass objects representing languages installed under the given company.
getAllUninstallable()
Retrieves a list of all languages that cannot be uninstalled for this company
public
getAllUninstallable(int $company_id) : array<string|int, mixed>
Parameters
- $company_id : int
-
The ID of the company whose uninstallable languages to fetch
Return values
array<string|int, mixed> —A list of uninstallable languages
getAvailable()
Get all available languages on the file system
public
getAvailable() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of key/value pairs representing languages available on the file system. Where the key is the language code and the value is the name of the language in its native form.
validateCodeExists()
Validates whether or not the $code and $company_id combination already exists
public
validateCodeExists(string $code, int $company_id) : bool
Parameters
- $code : string
-
The ISO 639-1 ISO 3166-1 alpha-2 code in concatenated format (e.g. "en_us")
- $company_id : int
-
The company ID
Return values
bool —True if the $code and $company_id combination already exists, false otherwise
validateDefaultLang()
Validates whether or not the $code and $company_id combination are the default language, or 'en_us'
public
validateDefaultLang(string $code, int $company_id) : bool
Parameters
- $code : string
-
The ISO 639-1 ISO 3166-1 alpha-2 code in concatenated format (e.g. "en_us")
- $company_id : int
-
The company ID
Return values
bool —True if the $code and $company_id are the default language or 'en_us', false otherwise
getDefaultLang()
Fetches the default language code for this company
private
getDefaultLang(int $company_id) : string
Parameters
- $company_id : int
-
The ID of the company whose default language to fetch
Return values
string —The language code (e.g. "en_us")
getNameFromFile()
Fetches the name of the language from the file system if the language exists and contains the language name file
private
getNameFromFile(string $code) : string
Parameters
- $code : string
-
The language code in ISO 639-1 ISO 3166-1 alpha-2 concatenated format (e.g. "en_us")
Return values
string —The name of the language from the language name file on the file system if it exists, else the $code.