Download the PHP package elaborate-code/jigsaw-localization without Composer

On this page you can find all versions of the php package elaborate-code/jigsaw-localization. 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 jigsaw-localization

Jigsaw localization

Packagist Version Packagist Downloads GitHub Workflow Status GitHub Workflow Status

banner

This package is built on top of PHP JSON tongue to bring localization feature to tightenco/jigsaw using JSON files.

Get started

Requirements

Setup

Install the package using composer:

Plug LoadLocalization to the builder by registering it in bootstrap.php:

Simple usage

Defining Translation Strings

  1. Create a lang folder in the root of your project.
  2. Create subfolders for each language/locale.
  3. Populate the subfolders with JSON files that hold translations using the original text as a key, and the translation as a value.

File structure example:

example

Retrieving Translation Strings

Source example:

The output:

Locale code format

two or three lowercase letters for the language code + optionally a dash (-) with two uppercase letters for the region code. For example, all the following codes ar, es, fr-CA, haw-US are considered valid.

The multi folder

For organizational purpose you can group internationalized translations in one JSON using many locale keys.

greetings.json example:

First level keys must be locale codes!

Using folder structure for locale code prefix

The default locale

First you need to define defaultLocale in config.php. If not set, the package will take en as a default.

The translation helper

If you call the __ helper without providing a locale parameter, it will try to resolve it from the page path.

If you provide the __ helper with the locale parameter it will proceed with it and ignore the folder structure.

The folder structure

domain.com/{locale}/path

Pages that reside in the web root folder source are assumed to be rendered using the defaultLocale. Other pages that reside in subfolders named after a locale code have their locale set to the subfolder name

The included page trick

You may find your self creating a fully coded source/index.blade.php and repeating the same code in source/fr/index.blade.php and for other locales. To avoid that we suggest the following approach:

  1. Create a source/_pages directory which will contain the master pages.
  2. A master page will look like any other ordinary page, _it will have the HTML structure and calls to __ but no hardcoded $current_locale value_ .For example You may directly copy the content of source/index.blade.php to source/_pages/index.blade.php.
  3. Include the master page into other pages that are locale aware.
  4. The included content will be able to know which locale to apply on the translation helper __ calls as a $current_locale.

Helpers

IMPORTANT: All the following helpers will try to resolve the locale code from the path if needed!

Setting baseUrl in the config is essential if your site root URL isn't 'domain.com/index.html'

current_path_locale

Returns the current page locale deduced from its path.

Usage example:

translate_path

When you have a page that is available in many locales. translate_path helps you get the equivalent translated path.

input/output examples:

current path translated path current_locale to target_locale
"/" "/fr" default -> fr
"/contact" "/fr/contact" default -> fr
"/fr" "/" fr -> default
"/fr/contact" "/contact" fr -> default
"/es/contact" "/fr-CA/contact" es -> fr-CA
"/es" "/fr-CA" es -> fr-CA

Usage example:

translate_url

Just like the translate_path helper, but it prepends the baseUrl if set in the config.

locale_path

To avoid hard coding the current_locale into paths, input only the partial path that comes after the locale code part into this helper and it will handle the rest for you.

$partial_path current_locale href
"/" DEFAULT "/"
"/" "fr" "/fr"
"/contact" DEFAULT "/contact"
"/contact" "fr" "/fr/contact"

locale_url

Just like the locale_path helper, but it prepends the baseUrl if set in the config.

Live test

Wanna see a project that is up and running with this library? checkout this repo

TODO

Contributing

Any help is very welcomed, feel free to fork and PR :)


All versions of jigsaw-localization with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
elaborate-code/php-json-tongue Version ^1.0
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 elaborate-code/jigsaw-localization contains the following files

Loading the files please wait ....