Localization class for easy translation management.
README will be fully filled after development of the class.
Created a class for handling translations. I though maybe somebody finds this useful.
Install the latest version using composer:
composer require dees040/loca
Make sure you require the autoload.
Loca::prepare() to configure the class.
prepare() takes one argument which is an array.
- locale (string): The country code of the main language to use.
- fallbackLocale (string): The country code of the fallback language to use.
- langDir (string): The full path to the directory which contains the translations.
Loca::prepare([ 'locale' => 'fr', 'fallbackLocale' => 'en', 'langDir' => '/var/www/Loca/resources/languages', ]);
Language strings are stored in files within the specified directory. Within this directory there should be a subdirectory for each language supported by the application:
/languageDirectory /en app.php /fr app.php
All language files simply return an array of keyed strings. For example:
<?php return [ 'welcome' => 'Welcome to our application.' ];
At this moment you can call a translation:
Which outputs: Welcome to our application.