PHP code example of germania-kg / i18n

1. Go to this page and download the library: Download germania-kg/i18n 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/ */

    

germania-kg / i18n example snippets



use Germania\i18n\GettextMiddleware;

$locale = "en_GB";
$domains = ["app", "project"];
$path = "./locales";

$middleware = new GettextMiddleware($locale, $domains, $path);


use Germania\i18n\LanguageNormalizer;

$norm = new LanguageNormalizer;
$norm("de-de"); // "de_DE"


use Germania\i18n\Translator;

$t = new Translator("de", "en");

echo $t("Just a string, nothing to translate");
// "Just a string, nothing to translate"

$var = array(
  "de" => "Deutsch: Nur eine String-Variable",
  "en" => "English: Just a string variable"
);

echo $t($var);
// "Deutsch: Nur eine String-Variable"

echo $t($var, "en");
// "English: Just a string variable"


use Germania\i18n\DGettextRenderer;

$domain = "app";
$dgr = new DGettextRenderer($domain);

echo $dgr("MsgId");
// "Some translated {placeholder} messages"

echo $dgr("MsgId", [
  "placeholder" => "success"
]);
// "Some translated success messages"