This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Translation functionality for PHP

1.1.0 2017-11-29 15:02 UTC

This package is not auto-updated.

Last update: 2021-11-27 13:34:39 UTC


Felicity translate provides a way to set and get translations in PHP


Set your locale, default locale, and translations with Felicity Config and then use the translation class to get your translations.


use felicity\config\Config;
use felicity\translate\Translate;

Config::set('lang.defaultLocale', 'en');
Config::set('lang.locale', 'de');

Config::set('lang.translations.en.myCategory', [
    'myTranslationKey' => 'Translation of something',
    'anotherTranslationKey' => 'Translation of something with {{var}}',

Config::set('lang.translations.de.myCategory', [
    'myTranslationKey' => 'Übersetzung von etwas',
    'anotherTranslationKey' => 'Übersetzung von etwas mit {{var}}',

$myTranslation = Translate::get('myCategory', 'myTranslationKey');
$anotherTranslation = Translate::get('myCategory', 'anotherTranslationKey', [
    '{{var}}' => 'someVal',

Usage in Felicity Twig

If you have required Felicity Twig into your project, you can use translations in twig as follows:

{# As a function #}
{{ translate('myTranslation', 'optionalCategory') }}

{# As a filter #}
{{ 'myTranslation'|translate('optionalCategory') }}

If you do not provide a category, the default will be used, which is dev unless you set a default with Felicity Config:


use felicity\config\Config;

Config::set('lang.defaultTwigCategory', 'myCategory');


Copyright 2017 BuzzingPixel, LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.