Skip to content

Commit 1b1beb9

Browse files
committed
Start on new localization glue system
1 parent 227e83f commit 1b1beb9

10 files changed

Lines changed: 133 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
/**
4+
* Glue to connect one or more translation/locale systems to the rest
5+
*
6+
* @author Hanne Moa, UNINETT AS. <hanne.moa@uninett.no>
7+
* @package SimpleSAMLphp
8+
*/
9+
10+
namespace SimpleSAML\Locale;
11+
12+
class Localization
13+
{
14+
15+
/**
16+
* The configuration to use.
17+
*
18+
* @var \SimpleSAML_Configuration
19+
*/
20+
private $configuration;
21+
22+
/**
23+
* The default gettext domain.
24+
*/
25+
private $domain = 'ssp';
26+
27+
/*
28+
* The locale directory
29+
*/
30+
private $localeDir;
31+
32+
/**
33+
* Constructor
34+
*
35+
* @param \SimpleSAML_Configuration $configuration Configuration object
36+
*/
37+
public function __construct(\SimpleSAML_Configuration $configuration)
38+
{
39+
$this->configuration = $configuration;
40+
$this->localeDir = $this->configuration->resolvePath('locales');
41+
$this->language = new Language($configuration);
42+
$this->i18nBackend = $this->configuration->getString('language.i18n.backend', null);
43+
$this->setupL10N();
44+
}
45+
46+
private function setupL10N() {
47+
// use old system
48+
if (is_null($this->i18nBackend)) {
49+
return;
50+
}
51+
$encoding = "UTF-8";
52+
$langcode = $this->language->getPosixLanguage($this->language->getLanguage());
53+
// use gettext and Twig.I18n
54+
if ($this->i18nBackend == 'twig.i18n') {
55+
putenv('LC_ALL='.$langcode);
56+
setlocale(LC_ALL, $langcode);
57+
bindtextdomain($this->domain, $this->localeDir);
58+
bind_textdomain_codeset($this->domain, $encoding);
59+
}
60+
}
61+
62+
63+
public function activateDomain($domain)
64+
{
65+
if ($this->i18nBackend == 'twig.i18n') {
66+
textdomain($domain);
67+
}
68+
}
69+
70+
71+
public function restoreDefaultDomain()
72+
{
73+
if ($this->i18nBackend == 'twig.i18n') {
74+
textdomain($this->domain);
75+
}
76+
}
77+
}
78+

locales/.gitkeep

Whitespace-only changes.

locales/en/LC_MESSAGES/ssp.mo

495 Bytes
Binary file not shown.

locales/en/LC_MESSAGES/ssp.po

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
msgid ""
2+
msgstr ""
3+
"Project-Id-Version: \n"
4+
"POT-Creation-Date: 2016-03-01 14:40+0100\n"
5+
"PO-Revision-Date: 2016-03-01 14:42+0100\n"
6+
"Last-Translator: Hanne Moa <hanne.moa@uninett.no>\n"
7+
"Language-Team: \n"
8+
"MIME-Version: 1.0\n"
9+
"Content-Type: text/plain; charset=UTF-8\n"
10+
"Content-Transfer-Encoding: 8bit\n"
11+
"X-Generator: Poedit 1.8.4\n"
12+
"X-Poedit-Basepath: .\n"
13+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
14+
"Language: en\n"
15+
16+
msgid "Hello, Untranslated World!"
17+
msgstr "Hello, Translated World!"

locales/en_US

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
en

locales/nb/LC_MESSAGES/ssp.mo

525 Bytes
Binary file not shown.

locales/nb/LC_MESSAGES/ssp.po

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
msgid ""
2+
msgstr ""
3+
"Project-Id-Version: \n"
4+
"POT-Creation-Date: 2016-03-01 14:40+0100\n"
5+
"PO-Revision-Date: 2016-03-01 14:45+0100\n"
6+
"Last-Translator: Hanne Moa <hanne.moa@uninett.no>\n"
7+
"Language-Team: \n"
8+
"MIME-Version: 1.0\n"
9+
"Content-Type: text/plain; charset=UTF-8\n"
10+
"Content-Transfer-Encoding: 8bit\n"
11+
"X-Generator: Poedit 1.8.4\n"
12+
"X-Poedit-Basepath: .\n"
13+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
14+
"Language: nb\n"
15+
"X-Poedit-SourceCharset: UTF-8\n"
16+
17+
msgid "Hello, Untranslated World!"
18+
msgstr "Hallo, oversatte verden!"

locales/nb_NO

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nb

locales/nn/LC_MESSAGES/ssp.mo

523 Bytes
Binary file not shown.

locales/nn/LC_MESSAGES/ssp.po

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
msgid ""
2+
msgstr ""
3+
"Project-Id-Version: \n"
4+
"POT-Creation-Date: 2016-03-01 14:40+0100\n"
5+
"PO-Revision-Date: 2016-03-01 14:45+0100\n"
6+
"Last-Translator: Hanne Moa <hanne.moa@uninett.no>\n"
7+
"Language-Team: \n"
8+
"MIME-Version: 1.0\n"
9+
"Content-Type: text/plain; charset=UTF-8\n"
10+
"Content-Transfer-Encoding: 8bit\n"
11+
"X-Generator: Poedit 1.8.4\n"
12+
"X-Poedit-Basepath: .\n"
13+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
14+
"Language: nn\n"
15+
"X-Poedit-SourceCharset: UTF-8\n"
16+
17+
msgid "Hello, Untranslated World!"
18+
msgstr "Hallo, oversatte verd!"

0 commit comments

Comments
 (0)