Brings localization feature to tightenco/jigsaw using JSON files

Overview

Jigsaw localization

Brings localization feature to tightenco/jigsaw using JSON files.

Get started

Setup

Bring jigsaw-localization to your Jigsaw project.

composer require elaborate-code/jigsaw-localization

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



// bootstrap.php

use ElaborateCode\JigsawLocalization\LoadLocalization;

$events->beforeBuild([LoadLocalization::class]);

Simple usage

Defining Translation Strings

  1. Create a lang folder in the root of your project.
  2. Create subfolders for each language supported by the application.
  3. Populate the subfolders with JSON files that hold translations using translation strings as keys (as much as you want).

File structure example:

/lang
    /en
        homepage.json
        aboutpage.json
        ...
    /fr
        homepage.json
        aboutpage.json
        ...
    ...

lang\en\homepage.json example:

{
    "Good morning": "Good morning",
    "view": "view",
    "fast": "fast",
}

lang\fr\homepage.json example:

{
    "Good morning": "bonjour",
    "view": "vue",
    "fast": "vite",
}

Retrieving Translation Strings

Source files example:

">
// source\index.blade.php

{{ $page->__("Good morning", 'en') }}

">
// source\fr\index.blade.php

{{ $page->__("Good morning", 'fr') }}

The outputted files:



<h2> Good morning h2>


<h2> Bonjour h2>

Using folder structure for lang prefix

This section explains how to dump the __ helper second argument for a more intuitive approach.

echo $page->__($text);

The default lang

First you should know that this package takes in consideration a parameter named default_lang. It set it to en by default but you can change it to any other value using default_lang key in config.php



// config.php

return [
    // ...
    'default_lang' => 'es',
    // ...
];

Note that the explicit $lang argument has higher precedence than the lang deduced from the folder structer!

The folder structure

example.com/{lang}

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

/source
    /fr
        index.blade.php
        contact.blade.php
        about.blade.php
        ...
    /es
        index.blade.php
        contact.blade.php
        about.blade.php
        ...
    ...
    index.blade.php
    contact.blade.php
    about.blade.php
    ...

The special multi folder

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

/lang
    ...
    /multi
        salutations.json
        projects_short_descriptions.json
        ...

salutations.json example:

{
    "en":{
        "Hello": "Hello",
        "Goodbye": "Goodbye"
    },
    "fr":{
        "Hello": "Salut",
        "Goodbye": "Au revoir"
    },
    "es":{
        "Hello": "Hola",
        "Goodbye": "Adiós"
    }
}

First level keys must be lang codes

The included page trick

One of the tricks to not repeat your self by creating the same page many times. You can create a source/_pages folder which will contain the master pages where you write the HTML code and call the __ helper then include that page in the other empty files that only respects the languages folder structure or define a $lang variable.

/source
    /_pages
        index.blade.php
        contact.blade.php
        ...
    /fr
        index.blade.php
        contact.blade.php
        ...
    index.blade.php
    contact.blade.php
    ...
// Both /source/index.blade.php and /source/fr/index.blade.php
@include('_pages.index')

Live test

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

TODO

  • A helper that gives a route to an equivalent translated page (done, I will integrate it soon).
  • Add get_current_lang helper.
  • Add testing.
  • Check the minimum required PHP version.
  • Automated github actions for testing.
  • Check behavior with non A-Z languages.
  • Support 5 caracters language codes xx_YY.

Contributing

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

You might also like...
Localization Helper - Package for convenient work with Laravel's localization features and fast language files generation
Localization Helper - Package for convenient work with Laravel's localization features and fast language files generation

Localization Helper Package for convenient work with Laravel's localization features and fast language files generation. Installation Via Composer $ c

JSONFinder - a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

JSONFinder - a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

A Symfony Feature Flag Bundle which easily allows you to configure and use your favorite feature flag provider.

Metro Markets FF Metro Markets FF is a Feature Flag Symfony Bundle. It easily allows you to configure and use your favorite feature flag provider. Ins

Allows generate class files parse from json and map json to php object, including multi-level and complex objects;

nixihz/php-object Allows generate class files parse from json and map json to php object, including multi-level and complex objects; Installation You

Provide CSV, JSON, XML and YAML files as an Import Source for the Icinga Director and optionally ship hand-crafted additional Icinga2 config files
Provide CSV, JSON, XML and YAML files as an Import Source for the Icinga Director and optionally ship hand-crafted additional Icinga2 config files

Icinga Web 2 Fileshipper module The main purpose of this module is to extend Icinga Director using some of it's exported hooks. Based on them it offer

route:menu gives you a beautiful route list which is friendly on smaller terminals and brings a few new features in.
route:menu gives you a beautiful route list which is friendly on smaller terminals and brings a few new features in.

Laravel Route Menu Your route:list, sir. route:menu gives you a beautiful route list which is friendly on smaller terminals and brings a few new featu

Livewire component that brings Spotlight/Alfred-like functionality to your Laravel application.
Livewire component that brings Spotlight/Alfred-like functionality to your Laravel application.

About LivewireUI Spotlight LivewireUI Spotlight is a Livewire component that provides Spotlight/Alfred-like functionality to your Laravel application.

Brings Laravel's great template engine, Blade, to WordPress

###This plugin is deprecated in favor of ekandreas/bladerunner WordPress Blade Brings Laravel's great template engine, Blade, to WordPress. Just insta

Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.
Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.

Laravel Befriended Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked

Livewire component that brings Spotlight/Alfred-like functionality to your Laravel application.
Livewire component that brings Spotlight/Alfred-like functionality to your Laravel application.

About Wire Elements Spotlight Wire Elements Spotlight is a Livewire component that provides Spotlight/Alfred-like functionality to your Laravel applic

GetCandy is a package that brings functionality akin to Shopify and other e-commerce platforms to Laravel.

GetCandy is a set of Laravel packages that bring functionality akin to Shopify and other e-commerce platforms to Laravel. You have complete freedom to

This package brings back the policy authorization for MenuItem

This package brings back the policy authorization for MenuItem. Also, the well-known canSee method is added to MenuItem and MenuSection. Empty menu sections are automatically hidden.

Foil brings all the flexibility and power of modern template engines to native PHP templates

Foil brings all the flexibility and power of modern template engines to native PHP templates. Write simple, clean and concise templates with nothing more than PHP.

This Kirby V3 Plugin brings snippets and blueprints together in one place. It includes useful tools that completely changing the way you work with Kirby: Fast and well organized.
This Kirby V3 Plugin brings snippets and blueprints together in one place. It includes useful tools that completely changing the way you work with Kirby: Fast and well organized.

Kirby Components Overview Do you love to make awesome projects with Kirby CMS? Do you also find it difficult to switch between snippets and blueprints

Easy localization for Laravel

Laravel Localization Easy i18n localization for Laravel, an useful tool to combine with Laravel localization classes. The package offers the following

A Laravel Larex plugin to import/export localization strings from/to Crowdin
A Laravel Larex plugin to import/export localization strings from/to Crowdin

Laravel Larex: Crowdin Plugin A Laravel Larex plugin to import/export localization strings from/to Crowdin 📋 Requirements PHP 7.4 | 8.0 Laravel ≥ 7 L

Laravel URL Localization Manager - [ccTLD, sub-domain, sub-directory].
Laravel URL Localization Manager - [ccTLD, sub-domain, sub-directory].

Laravel URL Localization - (ccTLD, sub-domain, sub-directory). with Simple & Easy Helpers. Afrikaans Akan shqip አማርኛ العربية հայերեն অসমীয়া azərbayca

A self-hosting localization tool

Localiser A self-hosting localization tool. Requirements PHP ^7.3 Usage Fetch cached locales GET

Easy Localization for Laravel
Easy Localization for Laravel

Query String Localization Package for Laravel Use this package to localize your laravel application via query strings easily. Features: Localization b

Releases(v1.1.0)
  • v1.1.0(Oct 2, 2022)

  • v1.0.0(Oct 2, 2022)

    What's Changed

    • Pest + Rearchitecture by @medilies in https://github.com/elaborate-code/jigsaw-localization/pull/1
    • Helper functions+testing by @medilies in https://github.com/elaborate-code/jigsaw-localization/pull/2

    New Contributors

    • @medilies made their first contribution in https://github.com/elaborate-code/jigsaw-localization/pull/1

    Full Changelog: https://github.com/elaborate-code/jigsaw-localization/compare/0.0.5...v1.0.0

    Source code(tar.gz)
    Source code(zip)
  • 0.0.5(Jul 3, 2022)

    • Expanded docs
    • Renamed helpers to fully replace the word route with 'url'
    • New url helper
    • Refactored helpers.
    • Edited syntax for more consistency.

    Full Changelog: https://github.com/elaborate-code/jigsaw-localization/compare/0.0.3...0.0.5

    Source code(tar.gz)
    Source code(zip)
  • 0.0.3(Jul 2, 2022)

    • First doc

    • Spell checks

    • Using DIRECTORY_SEPARATOR instead of \\.

    • No warning! Throwing exception when plugged to builder and there is no lang folder.

    • FIX: merging translations into config https://github.com/elaborate-code/jigsaw-localization/commit/ab933786aa7724c8429ed5ce56d7151da83efd6d#diff-ec1742447ab3e23acaa53d308e89a6a7b27133783110e65410699e729fbc1872L71

    • Helpers:

    Full Changelog: https://github.com/elaborate-code/jigsaw-localization/compare/0.0.1-stable...0.0.3

    Source code(tar.gz)
    Source code(zip)
  • 0.0.1-stable(Jun 30, 2022)

Owner
Elaborate Code
IT Services and IT Consulting
Elaborate Code
A self-hosting localization tool

Localiser A self-hosting localization tool. Requirements PHP ^7.3 Usage Fetch cached locales GET

Memo Chou 6 Mar 10, 2022
🎌 Laravel Localization Helper :: Easily add translation variables from Blade templates.

LocalizationHelper Package for convenient work with Laravel's localization features and fast language files generation. Take a look at contributing.md

Awes.io 36 Jul 18, 2022
Provides support for message translation and localization for dates and numbers.

The I18n library provides a I18n service locator that can be used for setting the current locale, building translation bundles and translating messages. Additionally, it provides the Time and Number classes which can be used to output dates, currencies and any numbers in the right format for the specified locale.

CakePHP 26 Oct 22, 2022
A GUI for managing JSON translation files in your laravel projects.

Laravel Language Manager Langman is a GUI for managing your JSON language files in a Laravel project. Installation Begin by installing the package thr

Mohamed Said 515 Nov 30, 2022
PHP library to collect and manipulate gettext (.po, .mo, .php, .json, etc)

Gettext Note: this is the documentation of the new 5.x version. Go to 4.x branch if you're looking for the old 4.x version Created by Oscar Otero http

Gettext 651 Dec 29, 2022
Check if a translated value in a JSON column is unique in the database.

Laravel Unique Translation IMPORTANT: March 2022 It's horrible to see what is happening now in Ukraine, as Russian army is bombarding houses, hospital

CodeZero 110 Dec 30, 2022
Language files manager in your artisan console.

Laravel Langman Langman is a language files manager in your artisan console, it helps you search, update, add, and remove translation lines with ease.

Mohamed Said 867 Nov 30, 2022
Manage Laravel translation files

Laravel 5 Translation Manager For Laravel 4, please use the 0.1 branch! This is a package to manage Laravel translation files. It does not replace the

Barry vd. Heuvel 1.5k Jan 4, 2023
A Gui To Manage Laravel Translation Files

Lingo A file based translation manager, which unlike other Lang managers don't need a database connection to handle the translation. Installation comp

Muah 97 Dec 5, 2022
This package allows to translate text using Google Translator for free without api.

Text Translator for PHP This package allows text translation using Google Translate for free without an API. It extracts the translated text from the

The Jano 3 Nov 7, 2022