Download the PHP package crosa7/leaf-omniglot without Composer

On this page you can find all versions of the php package crosa7/leaf-omniglot. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package leaf-omniglot



Leaf Omniglot



Latest Stable Version Total Downloads License

Leaf Omniglot is a simple but powerful module that adds multi language capabilities to your leaf applications.

Installation

You can easily install Leaf Omniglot using Composer.

//: # () //: # ()

Quick Start Guide

Create translation folder and files

Initialize Omniglot

In your index.php file (if using MVC: public/index.php). Add these lines:

Add Language Switch Route

In your routes file ("_app.php" for MVC and "index.php" for base Leaf) add this line:

Start Translating

Now in your template file you can add the following:

(this example is using laravel blade as template engine but you can adjust according to your template engine)

Or in a simple index.php file

You should now see in your browser a dropdown with "en_US" as option and inside the "h1" tag the text: Hello World

You can now add another translation file with the same translation key but a different value
and see that the dropdown now has a new option and that you can click on it and switch language.

For example:

Now if you switch to "pt_PT" in the dropdown you should see the text: Ola Mundo

Basic Usage

After installing omniglot, you need to create a folder where your translation files will live. Inside this folder you create the files in the following way:

The important part is having a file suffixed with .locale.json the name for the language does not matter. You can use for example en.locale.json as well

Translation file content

Your translation files should have the following format:

As key in the json, you have the translation key, used to identify the translation and as value you have the translation itself in the language that you defined in the filename

Init

Initialize the module and pass your custom configuration

Configurations

These are the available configuration parameters that you can pass inside the init() method as seen above.

DEFAULT_LOCALE

With this parameter you define your default locale so that this is the initial locale used in your application load. The value configured here MUST match the translation file name that you define for this locale. Example:

TRANSLATION_FILES_LOCATION

As the name says, this is the path to the folder that contains the translation files, one suggestion would be: 'TRANSLATION_FILES_LOCATION' => './locales' and then put the translation files inside a locales folder.

LOCALE_STRATEGY

With this you defined the way that you want Omniglot to behave when fetching and storing the chosen locale. Possible values are: session, accept-language-header and custom.

CUSTOM_LOCALE_STRATEGY_CLASS_NAME

After setting LOCALE_STRATEGY to custom and implementing your own class that implements the mentioned interface.
You set here the class name of your new class, example:

Available methods

tl()

This method you can call from anywhere in functional mode and is the main method for translating you strings. This method takes two parameters:

omniglot()

This method allows you to use any method inside the Omniglot class. For example you could use omniglot()->translate() instead of tl(). The following methods are available under omniglot():

omniglot()->addLanguageSwitchRoute()

You can call this method in the same file where you define your routes. For Leaf MVC / API that would be _app.
For a simple Leaf application it would be in index.php.

This will automatically create a POST route for you to call when you want to switch language.
You simply need to do a POST to /language/switch, with the following POST data:

``

And it will set this as current locale if the corresponding file exists. It will also redirect back to the page it was called from.

It also accepts 3 parameters.

Links/Projects


All versions of leaf-omniglot with dependencies

PHP Build Version
Package Version
Requires leafs/http Version ^2.3
leafs/session Version ^2.0
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package crosa7/leaf-omniglot contains the following files

Loading the files please wait ....