Download the PHP package folded/translation without Composer
On this page you can find all versions of the php package folded/translation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package translation
folded/history
Translate terms for your web app.
Summary
- About
- Features
- Requirements
- Installation
- Examples
- Version support
About
I created this package to have a standalone, easy way to use translation in my web app. This library is based on Laravel's translation engine.
Folded is a constellation of packages to help you setting up a web app easily, using ready to plug in packages.
- folded/action: A way to organize your controllers for your web app.
- folded/config: Configuration utilities for your PHP web app.
- folded/crypt: Encrypt and decrypt strings for your web app.
- folded/exception: Various kind of exception to throw for your web app.
- folded/file: Manipulate files with functions for your web app.
- folded/history: Manipulate the browser history for your web app.
- folded/http: HTTP utilities for your web app.
- folded/orm: An ORM for you web app.
- folded/routing: Routing functions for your PHP web app.
- folded/request: Request utilities, including a request validator, for your PHP web app.
- folded/session: Session functions for your web app.
- folded/view: View utilities for your PHP web app.
Features
- Can translate terms in the desired language
- Can set a default language to fallback on
- Can use json and key based translations in the same time
- Can use pluralized translations
Requirements
- PHP version >= 7.4.0
- Composer installed
Installation
- 1. Install the package
- 2. Prepare the folders
- 3. Add the bootstrap code
1. Install the package
In your root folder, run this command:
2. Prepare the folders
To work, you need to have a folder that contains your translation. This is the recommended organization:
Inside the lang folders, you can use any organization that fits your needs, from key based translations to json based translation.
When using key based translation, you will likely put any files containing the key and translated terms in their according folder depending the language. Here is an example.
For example, the messages.php
file can contain this for the en folder:
And this for the fr folder:
Howether, if you want, you can use json based translation. A good use case with JSON based translation files is when you need to use the translated term as the key. JSON based translations files must leave in the immediate folder lang
, unless the previous key based method. Here is an example:
And here is the content of en.json
for example:
And here is the content of fr.json
:
3. Add the bootstrap code
As early as possible, configure the library:
Examples
Keep in mind that, at any moment, you can refer to the official Laravel translation documentation if you have some doubt.
- 1. Get a translated term
- 2. Use placeholders in translated term
- 3. Get a translated pluralized term
- 4. Change the lang before getting a translated term
1. Get a translated term by its key
In this example, we will get a translated term from a key based translation.
This implies you have this folder structure:
You can also get a translated term from the original term text itself. For this, we recommend using JSON based translation.
This implies you have this folder structure:
2. Use placeholders in translated term
In this example, we will put values in a translation that contains placeholders.
This implies you have a translation like following:
3. Get a pluralized translated term
In this example, will get a pluralizable term translation.
This implies you have the following folder structure:
And your messages.php
file in the en folder contains:
For more information, browse the Laravel pluralized translation documentation.
4. Change the lang before getting a translated term
In this example, we will change the lang right before getting the translated term.
Version support
7.3 | 7.4 | 8.0 | |
---|---|---|---|
v0.1.0 | ❌ | ✔️ | ❓ |