alex-kalanis/kw_langs

Langs for accessing translations in KWCMS

v2.0.0 2024-04-08 23:56 UTC

This package is auto-updated.

Last update: 2024-04-08 23:58:54 UTC


README

Build Status Scrutinizer Code Quality Latest Stable Version Minimum PHP Version Downloads License Code Coverage

Define used translations inside the KWCMS tree. Parse them and return them.

PHP Installation

composer.phar require alex-kalanis/kw_langs

(Refer to Composer Documentation if you are not familiar with composer)

Package info

This package contains example file from KWCMS bootstrap. Use it as reference.

This lang bootstrap is connected with KWCMS modules. Using it outside KWCMS means you need to know the tree structure of module system and positioning langs there.

The idea is about translations which are separated just by their key (in single namespace).

The basic language file itself is simple php file with defined array variable "$lang" in which are stored key-value pairs like in normal php array. You do not need to specify module - it will be automatically set into content array when language loads.

It's also possible to use your own loader which will read your translation files by your own rules. So you can connect reading translations from get_text module files and that all will still behave the same way. Just it's need to respect that loader's input is module and lang name and output is array of key-value pairs which will be set into translation array. Beware! Previously set translations can be overwritten!

For your own modules and for staying things separated my advice is to have lang key in form of "{module_name}.{key_itself}" - with dot as separator and module name as prefix.

Example:

For ['your internal system key' => 'output is %s, on %d']

print \kalanis\kw_langs\Lang::get('your internal system key', 'first param', 2);

And it returns 'output is first param, on 2'

The best usage is inside the translations classes across the other modules - you just fill Lang::get() with your keys to your translations. It is possible to make a whole class which returns the wanted translations which will be instance of ILang and then pass it into lang loader.