This package contains two interfaces shared by all translation services. The LanguageDetectionInterface is used to detect the current language for the user while the TranslatorInterface is used to translate strings.

4.0.x-dev 2016-07-08 08:28 UTC

This package is auto-updated.

Last update: 2024-03-15 03:34:27 UTC


Fine is a PHP internationalisation package. It will help you develop applications that support several languages. FINE means: Fine is not English :).

By default, translation is performed using PHP mapping files, but other implementation (database storage) can also by used. Fine is a Mouf package. This means you will have a nice graphical interface inside the Mouf framework to write your own translated messages.

In this document, we will describe how to use FINE to support several languages in your application.




Fine comes as a Composer package and requires the "Mouf" framework to run. The first step is therefore to install Mouf.

Once Mouf is installed, you can process to the Fine installation.

Install Fine

Edit your composer.json file, and add a dependency on mouf/utils.i18n.fine.

A typical composer.json file might look like this:

        "require": {
            "mouf/mouf": "~2.0.0",
            "mouf/utils.i18n.fine.translation-interface": "~4.0",
            "mouf/utils.i18n.fine.language-detection": "~4.0",
            "mouf/utils.i18n.fine.file-translator": "~4.0",
            "mouf/": "~4.0",
            "mouf/utils.i18n.fine.common": "~4.0"
        "autoload": {
            "psr-4": {
                "Test\\": "src/"

As you can see, there are a number of packages included:

To install the package. After yout composer, you must going to the Mouf interface and select Project -> Installation tasks Fine task menu

You could see the list of fine package that must install to use it. Fine task installtion

Click on button Run the x tasks.

The installation create all the instance to use fine:

  • The FineCacadingTranslator class is to cascading all your translator. If the first doesn't have the translation, the second is requested.... The first translator how has the response is returned. So the order of translators is very important.

  • Found the defaultTranslationService instance in Mouf, click on it. There is a table of TranslatorInterface Fine default instance screenshot

  • To add a new instance, please click on add an instance, don't forget to configure it! Fine add instance screenshot

  • To change the order, just drag and drop the instance before or after another Fine instance order screenshot

Your package is ready for the code!

Using interface

Create a translation

This interface can be use to add, edit or delete a translation. You can access to this interface with the menu HTML -> Fine -> Manage Translation. Fine install menu screenshot

On this interface there is a button to add a new translation. Fine install interface screenshot

A modal appears, in the title input you can set your fine key, in this example it's "test.key". Select you language, for example english and add it ith the "add" button. Fine install new translation screenshot

Enter a message in the text zone. And click on the "Save all Translations" button. Fine install message screenshot

In this page you can see your translation. Fine install display screenshot

The top right select is to diplay the language at the bottom of the modal. With this translation you can easily translate all message. Fine install translation screenshot

Edit translation

To edit a translation click on the key or directly on the translation. You can add a new language with the "add" tab in the modal.

Remove a translation

You can remove a translation with the cross on the language. After you can validate to remove only this language Fine install remove translation screenshot

To remove the full key, click on the bottom button "remove key" and validate it. Fine install remove key screenshot

In your code

In your code, you can use the functions. There are bind automatically to the defaultTranslationService:

  • iMsg function: Return the translation of the key, parameters (in option) and LanguageDetection (in option)
  • eMsg function: Do an echo of iMsg


$string = iMsg('mykey', array('parameter1' => 'value'));
eMsg('mykey', array('parameter1' => 'value'));

The messagethe key mykey is: "A test with {parameter1}"

It's possible to add an instance of LanguageDetectionInterface (for exemple to change the language in the middle of your code). Example: In this controller you have bind an instance of LanguageDetetionInterface named $fixEnglishLanguage So you can call the function with

iMsg('myKey', array('parameter1' => 'value'), $this->fixEnglishLanguage);

Interface Implementation

If you want to create your own package, you can see the implementation