Download the PHP package xfra35/f3-multilang without Composer

On this page you can find all versions of the php package xfra35/f3-multilang. 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 f3-multilang

Multilang

…for F3 polyglots!

This plugin for Fat-Free Framework provides a URL-friendly mean to localize your web site/app.

Demo: here.

Basic usage

Step 1:

Declare the languages of your app in the MULTILANG.languages variable:

The same declaration can be achieved in a configuration file using the following syntax:

NB1: each entry maps a language identifier (en, ja, es) to one or more locales. The language identifiers are arbitrary (english, en-GB, japan, etc) but remember: they will appear in your URLs.

NB2: The first defined language is considered as the primary language, which means it is set as FALLBACK. In our example, on a japanese page, the locales and dictionaries would be searched in the following order: ja-JP, ja, en-GB, en, en-US.

NB3: It is strongly advised to include a country-independant language code (en, ja, es, etc...) in the list of locales for a better browser language detection.

Step 2:

Start the plugin by instantiating the class, just before the call to $f3->run:

That's it!

Now every existing URL has been duplicated into as many languages you've declared, using identifiers as prefixes:

Root URL

By default, the root URL autodetects the browser language and performs a redirection to its root page.

In our example, a Spanish user would be redirected to /es while a Russian user would be redirected to /en (fallback to the primary language).

You can override this default behaviour by setting the MULTILANG.root to a custom handler:

Use case: display a splash page with the list of available languages.

Advanced usage

(requires the usage of route aliases)

Rewrite URLs

Each translated URL consists of a language identifier followed by the original URL:

You can customize the second part by setting the MULTILANG.rules variable. For example, in order to translate the Spanish URL above, you could write (assuming the route is named terms):

The same declaration can be achieved in a configuration file using the following syntax:

Exclude a language from a route

When translating a website, you may need to perform a progressive translation, route by route. It could also occur that some parts won't be localized at all (for example a blog).

For this purpose, you can remove a route for a specific language by setting it to FALSE:

A request to /es/blog will return a 404 error.

Global routes

Some routes have to stay language-independant, for example a captcha doesn't have to be localized. Also back offices often happen to be monolingual.

Those global routes are not rewritten: they keep their original URL. They are defined using the MULTILANG.global variable:

Each entry can be a route alias or a URI prefix.

NB: on a global route, the language is auto-detected by default. So in the case of a monolingual back office, you may need to force the language at the controller level.

Rerouting

If you're using named routes...

$f3->reroute will work as expected, that is to say, it will reroute to the current language URL of the provided named route. E.g:

If you're using unnamed routes...

In that case, you have to provide a language-prefixed URL to $f3->reroute:

If you'd prefer to give the short URL to the framework and have it automatically prefix the URL with the current language, use the $ml->reroute method provided by the plugin:

In the situation where you'd like to quickly localize an existing project with unnamed routes, and would prefer to avoid having to rewrite every $f3->reroute into $ml->reroute, you can simply use the framework's ONREROUTE hook:

Migration mode

When translating an existing monolingual site, it is often interesting to redirect the old monolingual URIs to the new multilingual ones. The plugin does it automatically for you if you set MULTILANG.migrate to TRUE.

Example:

Strict mode

When URLs are rewritten, an error is thrown if duplicate URLs are detected. E.g:

This behaviour is called "strict mode" and is enabled by default.

You can disable it by setting MULTILANG.strict to FALSE, in which case no error will be thrown.

Passthru mode

When starting a new monolingual project, it may be interesting to keep the dependency to the Multilang plugin while not altering routes, just in case one day the project turns multilingual.

The passthru mode is meant for this situation. Set MULTILANG.passthru to TRUE to enable it.

When the passthru mode is enabled, the plugin doesn't do much:

API

current

Return the language detected for the current URL

primary

Return the name of the primary language

auto

TRUE if language has been auto-detected

passthru

TRUE if passthru mode is enabled

locale()

Return the currently selected locale

NB: the value returned by this function can be different from what you're expecting if the locales configured in MULTILANG.languages are not present on your system.

displayLanguage( $iso )

Return the language name corresponding to the given ISO code

NB: the name is localized if the intl extension is installed, otherwise it is returned in English.

displayCountry( $iso )

Return the country name corresponding to the given ISO code

NB: the name is localized if the intl extension is installed, otherwise it is returned in English.

display( $iso )

Alias for displayLanguage( $iso ) [deprecated]

languages()

Return the list of available languages

locales()

Return the list of available locales (indexed by languages)

aliases()

Return the list of all aliases

(even those not available for the current language)

isLocalized( $name, $lang=NULL )

Check if a route is localized in a given language (default=current)

(localized = not global nor excluded)

isGlobal( $name )

Check if a route is global

alias( $name, $params=NULL, $lang=NULL )

Assemble url from alias name

This function is a language-aware version of $f3->alias().

reroute( $url=NULL, $permanent=FALSE )

Reroute to specified URI

This function is a language-aware version of $f3->reroute().

Use it if you want an automatic language prefix on unnamed routes. Cf. rerouting.

Potential improvements


All versions of f3-multilang with dependencies

PHP Build Version
Package Version
Requires bcosca/fatfree-core Version 3.*
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 xfra35/f3-multilang contains the following files

Loading the files please wait ....