# COMMENT
LABEL:
LOCALE-1: "Text for locale 1"
LOCALE-2: "Text for locale 2"
# Examples
hello:
en: "Hello!"
de-DE: "Hallo!"
de-AT: "Griaß di!"
points:
en: "%s Points"
de: "%s Punkte"
progress:
en: "Step %s of %s"
de: "Schritt %s von %s"
help:
en: "This is a rather long help text
that spans multiple lines."
de: "Das ist ein längerer Hilfetext
der über mehrere Zeilen geht."
PHP
<?php
require('localization/localization.php');
LOCALIZATION\INIT_FROM_FILE('localization.yaml');
LOCALIZATION\SET_LOCALE(@$_GET['lang']);
use function LOCALIZATION\L;
?>
- load localization dictionary from file
- set locale from URL parameter, or try to get it from browser (header), or use default (en-US) otherwise
- make localization function
L()
available in PHP
JS
<?=LOCALIZATION\INIT_JS()?>
- generate a <script> tag to make localization function
L()
available in JS
PHP
<?=L('LABEL')?>
JS
<script>L('LABEL')</script>
Examples
L('hello')
— Get localized stringL('points', 42)
— Get localized string, with a contained%s
replaced by the supplied argumentL('progress', 99, 100)
— Any number of arguments can be supplied, e.g., two
Given a requested label
and the current locale, e.g., de-DE
, the localized entries for that label in the dictionary are (in that order) searched for locales that
- exactly match
de-DE
- start with
de-DE
- exactly match
de
- start with
de
The first entry is selected if no locale matched.
The label
itself is returned if it's not contained in the dictionary.