Skip to content

Commit 56a00c8

Browse files
committed
extremely basic i18n
1 parent 6002908 commit 56a00c8

19 files changed

+107
-403
lines changed

autoload.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static function autoload($class)
2424

2525
public static function reload($reload = false)
2626
{
27-
$key = 'lbry-classes-4';
27+
$key = 'lbry-classes-5';
2828
if (ini_get('apc.enabled') && !$reload)
2929
{
3030
$classes = apc_fetch($key, $success);

controller/Controller.class.php

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public static function execute($uri)
4949
return ContentActions::executeHome();
5050
case '/fund':
5151
return CreditActions::executeFund();
52+
case '/fund-after':
53+
return ['fund/fund-after'];
54+
case '/goals':
55+
return ['fund/goals'];
5256
case '/get':
5357
case '/windows':
5458
case '/ios':

controller/action/ContentActions.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ContentActions extends Actions
1515

1616
public static function executeHome()
1717
{
18-
return ['page/home', [
18+
return ['content/home', [
1919
'totalUSD' => CreditApi::getTotalDollarSales(),
2020
'totalPeople' => CreditApi::getTotalPeople()
2121
]];

data/i18n/en.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
global:
2+
tagline: Play, Share, Earn.
3+
sentence: Watch, read and play in a decentralized digital library controlled by the community.
4+
email:
5+
disclaimer: You will receive 1-2 messages a month, only from LBRY, Inc. and only about LBRY. You can easily unsubscribe at any time.
6+
download:
7+
main:
8+
title: LBRY for %os%

data/i18n/pt.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
tagline: Play, Compartilhar, ganhem.
2+
sentence: Assistir, ler e jogar em uma biblioteca digital descentralizada controlado pela comunidade.
3+
download:
4+
main:
5+
title: LBRY para %os%

lib/i18n.class.php

+65-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* i18n dummy we'll be happy to have later
55
*/
66
function __($msg, $args = [])
7-
{
8-
return strtr($msg, $args);
7+
{
8+
return strtr(i18n::translate($msg), $args);
99
}
1010

1111
/**
@@ -15,9 +15,43 @@ function __($msg, $args = [])
1515
*/
1616
class i18n
1717
{
18-
public static function register() /*needed to trigger class include, presumably setup would happen here*/
18+
protected static
19+
$language = null,
20+
$translations = [],
21+
$country = null;
22+
23+
public static function register($culture = null) /*needed to trigger class include, presumably setup would happen here*/
24+
{
25+
if ($culture === null)
26+
{
27+
$urlTokens = $_SERVER['HTTP_HOST'] ? explode('.', $_SERVER['HTTP_HOST']) : [];
28+
$code = $urlTokens ? reset($urlTokens) : 'en';
29+
switch($code)
30+
{
31+
case 'pt':
32+
$culture = 'pt_PT'; break;
33+
case 'en':
34+
case 'www':
35+
default:
36+
$culture = 'en_US';
37+
}
38+
}
39+
40+
list($language, $country) = explode('_', $culture);
41+
static::$language = $language;
42+
static::$country = $country;
43+
44+
setlocale(LC_MONETARY, $culture . '.UTF-8');
45+
}
46+
47+
public static function getLanguage()
1948
{
20-
setlocale(LC_MONETARY, 'en_US.UTF-8');
49+
return static::$language;
50+
}
51+
52+
public static function getCountry()
53+
{
54+
return static::$country;
2155
}
2256

2357
public static function formatCurrency($amount, $currency = 'USD')
@@ -29,4 +63,31 @@ public static function formatCredits($amount)
2963
{
3064
return '<span class="formatted-credits">' . number_format($amount, 1) . ' LBC</span>';
3165
}
66+
67+
public static function translate($token, $language = null)
68+
{
69+
$language = $language === null ? static::$language : $language;
70+
if (!isset(static::$translations[$language]))
71+
{
72+
$path = ROOT_DIR . '/data/i18n/' . $language . '.yaml';
73+
static::$translations[$language] = file_exists($path) ? Spyc::YAMLLoadString(file_get_contents($path)) : [];
74+
}
75+
$scope = static::$translations[$language];
76+
foreach(explode('.', $token) as $level)
77+
{
78+
if (isset($scope[$level]))
79+
{
80+
$scope = $scope[$level];
81+
}
82+
else
83+
{
84+
$scope = [];
85+
}
86+
}
87+
if (!$scope && $language != 'en')
88+
{
89+
return static::translate($token, 'en');
90+
}
91+
return $scope ?: $token;
92+
}
3293
}

view/View.class.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public static function render($template, array $vars = [])
5050
throw $e;
5151
}
5252

53-
return ob_get_clean();
53+
54+
return static::interpolateTokens(ob_get_clean());
5455
}
5556

5657
public static function exists($template)
@@ -108,4 +109,11 @@ public static function compileCss()
108109
$css = $scssCompiler->compile(file_get_contents(ROOT_DIR.'/web/scss/all.scss'));
109110
file_put_contents(ROOT_DIR.'/web/css/all.css', $css);
110111
}
112+
113+
protected static function interpolateTokens($html)
114+
{
115+
return preg_replace_callback('/{{[\w\.]+}}/is', function($m) {
116+
return i18n::translate(trim($m[0], '}{'));
117+
}, $html);
118+
}
111119
}

view/template/page/home.php view/template/content/home.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
<div class="cover cover-dark">
88
<div class="content content-wide content-dark">
99
<div class="text-center">
10-
<h1 class="cover-title">Play, Share, Earn.</h1>
11-
<h2 class="cover-subtitle" style="max-width: 600px; margin-left: auto; margin-right: auto">
12-
Watch, read and play in a decentralized digital library controlled by the community.
13-
</h2>
10+
<h1 class="cover-title">{{tagline}}</h1>
11+
<h2 class="cover-subtitle" style="max-width: 600px; margin-left: auto; margin-right: auto">{{sentence}}</h2>
1412
</div>
1513

1614
<?php /*

view/template/download/get.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<main class="column-fluid">
66
<div class="span7">
77
<div class="cover cover-dark cover-dark-grad content content-stretch content-dark">
8-
<h1>LBRY for <?php echo $osTitle ?> <span class="<?php echo $osIcon ?>"></span></h1>
8+
<h1><?php echo strtr(__('download.main.title'), ['%os%' => $osTitle]) ?> <span class="<?php echo $osIcon ?>"></span></h1>
99
<?php if ($downloadHtml): ?>
1010
<?php echo View::render('download/_betaNotice') ?>
1111
<?php echo $downloadHtml ?>
File renamed without changes.
File renamed without changes.

view/template/mail/joinList.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
<?php endif ?>
2626
<?php if (isset($meta) && $meta): ?>
2727
<div class="meta">
28-
<?php echo __('You will receive 1-2 messages a month, only from LBRY, Inc. and only about LBRY.') ?>
29-
<?php echo __('You can easily unsubscribe at any time.') ?>
28+
{{email.disclaimer}}
3029
</div>
3130
<?php endif ?>
3231
</div>

view/template/page/docs.php

-65
This file was deleted.

view/template/page/learn-old.php

-70
This file was deleted.

view/template/page/learn.php

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php Response::setMetaDescription(__('Learn more about LBRY, the technology that puts you back in control of the internet.')) ?>
22
<?php Response::setMetaTitle(__('Learn About LBRY')) ?>
33
<?php echo View::render('nav/header', ['isDark' => false]) ?>
4-
54
<main class="column-fluid ">
65
<div class="span6">
76
<div class="cover cover-light content">

view/template/page/publish.php

-47
This file was deleted.

view/template/page/test.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php Response::setMetaDescription('WHAT WHAT') ?>
2+
<?php NavActions::setNavUri('/get') ?>
3+
<?php echo View::render('nav/header', ['isDark' => false]) ?>
4+
<main>
5+
<div class="content">
6+
<div class='prefinery-form-embed'></div>
7+
</div>
8+
</main>
9+
<script type="text/javascript">var _pfy = _pfy || [];(function(){function pfy_load(){var pfys=document.createElement('script');pfys.type='text/javascript';pfys.async=true;pfys.src='https://lbry.prefinery.com/widget/v2/whzquod5.js';var pfy=document.getElementsByTagName('script')[0];pfy.parentNode.insertBefore(pfys,pfy);}if (window.attachEvent){window.attachEvent('onload',pfy_load);}else{window.addEventListener('load',pfy_load,false);}})();</script>
10+
<?php echo View::render('nav/footer') ?>

0 commit comments

Comments
 (0)