Multilingual PHP Apps With Fat-Free Framework


This guide shows how to create a multilingual F3 app with ease. Localization is a important cornerstone for growing any app. It helps reaching a broader audience and improves the overall user experience.


I recently read a post about an amazing project done with Fat-Free Framework (or simply, “F3”), a PHP micro framework. So I gave it a try to find out how it handles localization.

Getting Started

The good new is: F3 has built-in support for multilingual apps. In this example, I will create a project with the following basic directory structure:

F3 automatically detects language files in the ‘dict’ directory. Even better: F3 detects a users language based on the HTTP Accept-Language header coming from the browser and uses the right language file.

Here is my minimal app code in index.php:

Creating Language Files

For this example I want to use two languages: English and German.

For English, I create a new file (en.php) in the ‘dict’ directory.

For German, I create de.php:

It is also possible to create language files for language variants, such as en-US, en-GB or de-DE, de-AT. If a key doesn’t exist in a variant, F3 will search for it in the root language and at last, always fall back to the default English ‘en.php’ language file.

Using Language Files In F3 Templates

Loading strings from the language files in to your templates is easy, here is my index.html template:

Use Translations In Your Code

I can also access translated strings from within the app code:

Advanced Translations

Some of the more advanced localization techniques that F3 supports are placeholders and pluralization.


In the language file:

In the app code:


The plural syntax is a bit tricky, but very helpful. Here is what the language file looks like:

Quantities recognized by F3 are ‘zero’, ‘one’, ‘two’ and ‘other’.

Usage in the app code:


As mentioned earlier, F3 automatically serves the right language. For testing purposes, if you don’t want to mess around in your browser language settings, you can force F3 to use a specific language file:

Managing Translations

Working with .php language files can be cumbersome: new keys must be added to each language file separately, the same goes for updating keys.

PhraseApp is a translation management tool that addresses some of the issues. It also features a powerful In-Context-Editor (Demo), making the process of translating web apps more convenient.

Integrating the PhraseApp In-Context-Editor in your F3 apps is easy. Get our special language file and save it in your ‘dict’ directory. Give it a two letter name that isn’t used, for example ‘xx.php’. In your app, force the use of the Phrase language file that exposes your keys to the PhraseApp editor:

Then include the JavaScript snippet in your templates:

That’s it – you can now translate your site using the PhraseApp In-Context-Editor. PhraseApp also lets you order professional translations. “Se habla Español” for your app? With PhraseApp, it’s just one click away.

Further Reading

Be sure to subscribe and receive all updates from the PhraseApp blog straight to your inbox. You’ll receive localization best practices, about cultural aspects of breaking into new markets, guides and tutorials for optimizing software translation and other industry insights and information. Don’t miss out!

Also published on Medium.