PHP code example of folded / translation

1. Go to this page and download the library: Download folded/translation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

folded / translation example snippets


return [
  "home" => [
    "title" => "Welcome in the home page",
  ],
];

return [
  "home" => [
    "title" => "Bienvenue sur la page d'accueil",
  ],
];

use function Folded\setDefaultTranslationLang;
use function Folded\setTranslationFolderPath;

setDefaultTranslationLang("en");
setTranslationFolderPath("path/to/folder");

use function Folded\getTranslation;

echo getTranslation("messages.home.title");

use function Folded\getTranslation;

echo getTranslation("Contact us for a custom tailored quotation");

use function Folded\getTranslation;

echo getTranslation("messages.home.welcome", ["name" => "John"]);

// lang/en/messages.php
return [
  "home" => [
    "welcome" => "Welcome, :name",
  ],
];

use function Folded\getVariableTranslation;

$numberOfPageViewed = 5000;

echo getVariableTranslation("messages.home.page-viewed", $numberOfPageViewed);

return [
  "home" => [
    "page-viewed" => "{0} No page viewed|[1] One page viewed|[2,*] :count page viewed",
  ]
];

use function Folded\setTranslationLang;
use function Folded\getTranslation;

setTranslationLang("fr");

echo getTranslation("messages.home.title");

.
└── lang/
    ├── en/
    │   └── messages.php
    └── fr/
        └── messages.php

.
└── lang/
    ├── en/
    │   └── messages.php
    ├── fr/
    │   └── messages.php
    ├── en.json
    └── fr.json
json
{
  "Contact us for a custom tailored quotation": "Contactez nous pour un devis sur-mesure"
}

.
└── lang/
    ├── en/
    │   └── messages.php
    └── fr/
        └── messages.php

.
└── lang/
    ├── en/
    │   └── messages.php
    └── fr/
        └── messages.php