feat: review comments

This commit is contained in:
Christy Jacob
2021-07-26 12:35:08 +05:30
parent e6e0baab12
commit 198c5087c7
9 changed files with 110 additions and 129 deletions
+3 -3
View File
@@ -958,7 +958,7 @@ App::get('/v1/account/logs')
$record = $geodb->get($log['ip']);
if ($record) {
$output[$i]['countryCode'] = $locale->getText('countries.'.strtolower($record['country']['iso_code']), '--');
$output[$i]['countryCode'] = $locale->getText('countries.'.strtolower($record['country']['iso_code']), false) ? \strtolower($record['country']['iso_code']) : '--';
$output[$i]['countryName'] = $locale->getText('countries.'.strtolower($record['country']['iso_code']), $locale->getText('locale.country.unknown'));
} else {
$output[$i]['countryCode'] = '--';
@@ -1516,7 +1516,7 @@ App::post('/v1/account/recovery')
$url = Template::unParseURL($url);
$body = Template::fromFile(__DIR__.'/../../config/locale/templates/email-base.tpl');
$content = Template::fromHtmlString($locale->getText('account.emails.recovery.body'));
$content = Template::fromString($locale->getText('account.emails.recovery.body'));
$cta = Template::fromFile(__DIR__.'/../../config/locale/templates/email-cta.tpl');
$body
@@ -1720,7 +1720,7 @@ App::post('/v1/account/verification')
$url = Template::unParseURL($url);
$body = Template::fromFile(__DIR__.'/../../config/locale/templates/email-base.tpl');
$content = Template::fromHtmlString($locale->getText('account.emails.verification.body'));
$content = Template::fromString($locale->getText('account.emails.verification.body'));
$cta = Template::fromFile(__DIR__.'/../../config/locale/templates/email-cta.tpl');
$body
+12 -1
View File
@@ -96,6 +96,10 @@ App::get('/v1/locale/countries')
]);
}
usort($output, function ($a, $b) {
return strcmp($a->getAttribute('name'), $b->getAttribute('name'));
});
$response->dynamic(new Document(['countries' => $output, 'sum' => \count($output)]), Response::MODEL_COUNTRY_LIST);
});
@@ -116,7 +120,6 @@ App::get('/v1/locale/countries/eu')
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Locale\Locale $locale */
$list = Config::getParam('locale-countries'); /* @var $countries array */
$eu = Config::getParam('locale-eu');
$output = [];
@@ -129,6 +132,10 @@ App::get('/v1/locale/countries/eu')
}
}
usort($output, function ($a, $b) {
return strcmp($a->getAttribute('name'), $b->getAttribute('name'));
});
$response->dynamic(new Document(['countries' => $output, 'sum' => \count($output)]), Response::MODEL_COUNTRY_LIST);
});
@@ -193,6 +200,10 @@ App::get('/v1/locale/continents')
]);
}
usort($output, function ($a, $b) {
return strcmp($a->getAttribute('name'), $b->getAttribute('name'));
});
$response->dynamic(new Document(['continents' => $output, 'sum' => \count($output)]), Response::MODEL_CONTINENT_LIST);
});
+1 -1
View File
@@ -420,7 +420,7 @@ App::post('/v1/teams/:teamId/memberships')
$url = Template::unParseURL($url);
$body = Template::fromFile(__DIR__.'/../../config/locale/templates/email-base.tpl');
$content = Template::fromHtmlString($locale->getText('account.emails.invitation.body'));
$content = Template::fromString($locale->getText('account.emails.invitation.body'));
$cta = Template::fromFile(__DIR__.'/../../config/locale/templates/email-cta.tpl');
$title = \sprintf($locale->getText('account.emails.invitation.title'), $team->getAttribute('name', '[TEAM-NAME]'), $project->getAttribute('name', ['[APP-NAME]']));
+1 -1
View File
@@ -318,7 +318,7 @@ App::get('/v1/users/:userId/logs')
$record = $geodb->get($log['ip']);
if ($record) {
$output[$i]['countryCode'] = $locale->getText('countries.'.strtolower($record['country']['iso_code']), '--');
$output[$i]['countryCode'] = $locale->getText('countries.'.strtolower($record['country']['iso_code']), false) ? \strtolower($record['country']['iso_code']) : '--';
$output[$i]['countryName'] = $locale->getText('countries.'.strtolower($record['country']['iso_code']), $locale->getText('locale.country.unknown'));
} else {
$output[$i]['countryCode'] = '--';
+56 -56
View File
@@ -252,62 +252,62 @@ $register->set('geodb', function () {
* Localization
*/
Locale::$exceptions = false;
Locale::setFromJSON('af', __DIR__.'/config/locale/translations/af.json');
Locale::setFromJSON('ar', __DIR__.'/config/locale/translations/ar.json');
Locale::setFromJSON('ba', __DIR__.'/config/locale/translations/ba.json');
Locale::setFromJSON('be', __DIR__.'/config/locale/translations/be.json');
Locale::setFromJSON('bg', __DIR__.'/config/locale/translations/bg.json');
Locale::setFromJSON('bn', __DIR__.'/config/locale/translations/bn.json');
Locale::setFromJSON('cat', __DIR__.'/config/locale/translations/cat.json');
Locale::setFromJSON('cz', __DIR__.'/config/locale/translations/cz.json');
Locale::setFromJSON('de', __DIR__.'/config/locale/translations/de.json');
Locale::setFromJSON('en', __DIR__.'/config/locale/translations/en.json');
Locale::setFromJSON('es', __DIR__.'/config/locale/translations/es.json');
Locale::setFromJSON('fa', __DIR__.'/config/locale/translations/fa.json');
Locale::setFromJSON('fi', __DIR__.'/config/locale/translations/fi.json');
Locale::setFromJSON('fo', __DIR__.'/config/locale/translations/fo.json');
Locale::setFromJSON('fr', __DIR__.'/config/locale/translations/fr.json');
Locale::setFromJSON('gr', __DIR__.'/config/locale/translations/gr.json');
Locale::setFromJSON('gu', __DIR__.'/config/locale/translations/gu.json');
Locale::setFromJSON('he', __DIR__.'/config/locale/translations/he.json');
Locale::setFromJSON('hi', __DIR__.'/config/locale/translations/hi.json');
Locale::setFromJSON('hu', __DIR__.'/config/locale/translations/hu.json');
Locale::setFromJSON('hy', __DIR__.'/config/locale/translations/hy.json');
Locale::setFromJSON('id', __DIR__.'/config/locale/translations/id.json');
Locale::setFromJSON('is', __DIR__.'/config/locale/translations/is.json');
Locale::setFromJSON('it', __DIR__.'/config/locale/translations/it.json');
Locale::setFromJSON('ja', __DIR__.'/config/locale/translations/ja.json');
Locale::setFromJSON('jv', __DIR__.'/config/locale/translations/jv.json');
Locale::setFromJSON('ka', __DIR__.'/config/locale/translations/ka.json');
Locale::setFromJSON('km', __DIR__.'/config/locale/translations/km.json');
Locale::setFromJSON('ko', __DIR__.'/config/locale/translations/ko.json');
Locale::setFromJSON('lt', __DIR__.'/config/locale/translations/lt.json');
Locale::setFromJSON('ml', __DIR__.'/config/locale/translations/ml.json');
Locale::setFromJSON('mr', __DIR__.'/config/locale/translations/mr.json');
Locale::setFromJSON('ms', __DIR__.'/config/locale/translations/ms.json');
Locale::setFromJSON('nl', __DIR__.'/config/locale/translations/nl.json');
Locale::setFromJSON('no', __DIR__.'/config/locale/translations/no.json');
Locale::setFromJSON('np', __DIR__.'/config/locale/translations/np.json');
Locale::setFromJSON('od', __DIR__.'/config/locale/translations/od.json');
Locale::setFromJSON('ph', __DIR__.'/config/locale/translations/ph.json');
Locale::setFromJSON('pl', __DIR__.'/config/locale/translations/pl.json');
Locale::setFromJSON('pt-br', __DIR__.'/config/locale/translations/pt-br.json');
Locale::setFromJSON('pt-pt', __DIR__.'/config/locale/translations/pt-pt.json');
Locale::setFromJSON('pa', __DIR__.'/config/locale/translations/pa.json');
Locale::setFromJSON('ro', __DIR__.'/config/locale/translations/ro.json');
Locale::setFromJSON('ru', __DIR__ . '/config/locale/translations/ru.json');
Locale::setFromJSON('si', __DIR__ . '/config/locale/translations/si.json');
Locale::setFromJSON('sl', __DIR__ . '/config/locale/translations/sl.json');
Locale::setFromJSON('sq', __DIR__ . '/config/locale/translations/sq.json');
Locale::setFromJSON('sv', __DIR__ . '/config/locale/translations/sv.json');
Locale::setFromJSON('ta', __DIR__ . '/config/locale/translations/ta.json');
Locale::setFromJSON('th', __DIR__.'/config/locale/translations/th.json');
Locale::setFromJSON('tr', __DIR__.'/config/locale/translations/tr.json');
Locale::setFromJSON('ua', __DIR__.'/config/locale/translations/ua.json');
Locale::setFromJSON('ur', __DIR__.'/config/locale/translations/ur.json');
Locale::setFromJSON('vi', __DIR__.'/config/locale/translations/vi.json');
Locale::setFromJSON('zh-cn', __DIR__.'/config/locale/translations/zh-cn.json');
Locale::setFromJSON('zh-tw', __DIR__.'/config/locale/translations/zh-tw.json');
Locale::setLanguageFromJSON('af', __DIR__.'/config/locale/translations/af.json');
Locale::setLanguageFromJSON('ar', __DIR__.'/config/locale/translations/ar.json');
Locale::setLanguageFromJSON('ba', __DIR__.'/config/locale/translations/ba.json');
Locale::setLanguageFromJSON('be', __DIR__.'/config/locale/translations/be.json');
Locale::setLanguageFromJSON('bg', __DIR__.'/config/locale/translations/bg.json');
Locale::setLanguageFromJSON('bn', __DIR__.'/config/locale/translations/bn.json');
Locale::setLanguageFromJSON('cat', __DIR__.'/config/locale/translations/cat.json');
Locale::setLanguageFromJSON('cz', __DIR__.'/config/locale/translations/cz.json');
Locale::setLanguageFromJSON('de', __DIR__.'/config/locale/translations/de.json');
Locale::setLanguageFromJSON('en', __DIR__.'/config/locale/translations/en.json');
Locale::setLanguageFromJSON('es', __DIR__.'/config/locale/translations/es.json');
Locale::setLanguageFromJSON('fa', __DIR__.'/config/locale/translations/fa.json');
Locale::setLanguageFromJSON('fi', __DIR__.'/config/locale/translations/fi.json');
Locale::setLanguageFromJSON('fo', __DIR__.'/config/locale/translations/fo.json');
Locale::setLanguageFromJSON('fr', __DIR__.'/config/locale/translations/fr.json');
Locale::setLanguageFromJSON('gr', __DIR__.'/config/locale/translations/gr.json');
Locale::setLanguageFromJSON('gu', __DIR__.'/config/locale/translations/gu.json');
Locale::setLanguageFromJSON('he', __DIR__.'/config/locale/translations/he.json');
Locale::setLanguageFromJSON('hi', __DIR__.'/config/locale/translations/hi.json');
Locale::setLanguageFromJSON('hu', __DIR__.'/config/locale/translations/hu.json');
Locale::setLanguageFromJSON('hy', __DIR__.'/config/locale/translations/hy.json');
Locale::setLanguageFromJSON('id', __DIR__.'/config/locale/translations/id.json');
Locale::setLanguageFromJSON('is', __DIR__.'/config/locale/translations/is.json');
Locale::setLanguageFromJSON('it', __DIR__.'/config/locale/translations/it.json');
Locale::setLanguageFromJSON('ja', __DIR__.'/config/locale/translations/ja.json');
Locale::setLanguageFromJSON('jv', __DIR__.'/config/locale/translations/jv.json');
Locale::setLanguageFromJSON('ka', __DIR__.'/config/locale/translations/ka.json');
Locale::setLanguageFromJSON('km', __DIR__.'/config/locale/translations/km.json');
Locale::setLanguageFromJSON('ko', __DIR__.'/config/locale/translations/ko.json');
Locale::setLanguageFromJSON('lt', __DIR__.'/config/locale/translations/lt.json');
Locale::setLanguageFromJSON('ml', __DIR__.'/config/locale/translations/ml.json');
Locale::setLanguageFromJSON('mr', __DIR__.'/config/locale/translations/mr.json');
Locale::setLanguageFromJSON('ms', __DIR__.'/config/locale/translations/ms.json');
Locale::setLanguageFromJSON('nl', __DIR__.'/config/locale/translations/nl.json');
Locale::setLanguageFromJSON('no', __DIR__.'/config/locale/translations/no.json');
Locale::setLanguageFromJSON('np', __DIR__.'/config/locale/translations/np.json');
Locale::setLanguageFromJSON('od', __DIR__.'/config/locale/translations/od.json');
Locale::setLanguageFromJSON('ph', __DIR__.'/config/locale/translations/ph.json');
Locale::setLanguageFromJSON('pl', __DIR__.'/config/locale/translations/pl.json');
Locale::setLanguageFromJSON('pt-br', __DIR__.'/config/locale/translations/pt-br.json');
Locale::setLanguageFromJSON('pt-pt', __DIR__.'/config/locale/translations/pt-pt.json');
Locale::setLanguageFromJSON('pa', __DIR__.'/config/locale/translations/pa.json');
Locale::setLanguageFromJSON('ro', __DIR__.'/config/locale/translations/ro.json');
Locale::setLanguageFromJSON('ru', __DIR__ . '/config/locale/translations/ru.json');
Locale::setLanguageFromJSON('si', __DIR__ . '/config/locale/translations/si.json');
Locale::setLanguageFromJSON('sl', __DIR__ . '/config/locale/translations/sl.json');
Locale::setLanguageFromJSON('sq', __DIR__ . '/config/locale/translations/sq.json');
Locale::setLanguageFromJSON('sv', __DIR__ . '/config/locale/translations/sv.json');
Locale::setLanguageFromJSON('ta', __DIR__ . '/config/locale/translations/ta.json');
Locale::setLanguageFromJSON('th', __DIR__.'/config/locale/translations/th.json');
Locale::setLanguageFromJSON('tr', __DIR__.'/config/locale/translations/tr.json');
Locale::setLanguageFromJSON('ua', __DIR__.'/config/locale/translations/ua.json');
Locale::setLanguageFromJSON('ur', __DIR__.'/config/locale/translations/ur.json');
Locale::setLanguageFromJSON('vi', __DIR__.'/config/locale/translations/vi.json');
Locale::setLanguageFromJSON('zh-cn', __DIR__.'/config/locale/translations/zh-cn.json');
Locale::setLanguageFromJSON('zh-tw', __DIR__.'/config/locale/translations/zh-tw.json');
\stream_context_set_default([ // Set global user agent and http settings
'http' => [
+1 -8
View File
@@ -45,7 +45,7 @@
"utopia-php/cache": "0.2.*",
"utopia-php/cli": "0.11.*",
"utopia-php/config": "0.2.*",
"utopia-php/locale": "dev-feat-accept-file-path",
"utopia-php/locale": "0.4.*",
"utopia-php/registry": "0.5.*",
"utopia-php/preloader": "0.2.*",
"utopia-php/domains": "1.1.*",
@@ -61,13 +61,6 @@
"adhocore/jwt": "1.1.2",
"slickdeals/statsd": "3.1.0"
},
"repositories": [
{
"url": "https://github.com/christyjacob4/locale.git",
"type": "git"
}
],
"require-dev": {
"appwrite/sdk-generator": "0.12.0",
"swoole/ide-helper": "4.6.7",
Generated
+17 -8
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "17590fc8cbf177a0c8e337ece9ca85b5",
"content-hash": "e0473ee4a24cd6e305347d69675c2332",
"packages": [
{
"name": "adhocore/jwt",
@@ -1858,11 +1858,17 @@
},
{
"name": "utopia-php/locale",
"version": "dev-feat-accept-file-path",
"version": "0.4.0",
"source": {
"type": "git",
"url": "https://github.com/christyjacob4/locale.git",
"reference": "0cc5b8f2771db7a0fd1e872705dd22450da7a975"
"url": "https://github.com/utopia-php/locale.git",
"reference": "c2d9358d0fe2f6b6ed5448369f9d1e430c615447"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/locale/zipball/c2d9358d0fe2f6b6ed5448369f9d1e430c615447",
"reference": "c2d9358d0fe2f6b6ed5448369f9d1e430c615447",
"shasum": ""
},
"require": {
"php": ">=7.4"
@@ -1877,6 +1883,7 @@
"Utopia\\Locale\\": "src/Locale"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@@ -1894,7 +1901,11 @@
"upf",
"utopia"
],
"time": "2021-07-22T18:54:44+00:00"
"support": {
"issues": "https://github.com/utopia-php/locale/issues",
"source": "https://github.com/utopia-php/locale/tree/0.4.0"
},
"time": "2021-07-24T11:35:55+00:00"
},
{
"name": "utopia-php/preloader",
@@ -6056,9 +6067,7 @@
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
"utopia-php/locale": 20
},
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
+15 -47
View File
@@ -5,11 +5,15 @@ namespace Appwrite\Template;
use Exception;
use Utopia\View;
use function PHPUnit\Framework\isReadable;
class Template extends View
{
/**
* @var string
*/
protected string $content = '';
/**
* fromFile
*
@@ -30,30 +34,25 @@ class Template extends View
return $template->setPath($path);
}
/**
* @var string
*/
protected string $html = '';
/**
* fromHtmlString
* fromString
*
* Creates a new Template() using raw HTML.
* Creates a new Template() using a raw string
*
* @param string $html
* @param string $content
*
* @return self
*
*/
public static function fromHtmlString(string $html): self
public static function fromString(string $content): self
{
if (empty($html)) {
throw new Exception('Empty HTML string');
if (empty($content)) {
throw new Exception('Empty string');
}
$template = new Template();
return $template->setHtml($html);
$template->content = $content;
return $template;
}
/**
@@ -74,8 +73,8 @@ class Template extends View
if (\is_readable($this->path)) {
$template = \file_get_contents($this->path); // Include template file
} else if (!empty($this->html)) {
$template = $this->print($this->html);
} else if (!empty($this->content)) {
$template = $this->print($this->content);
} else {
throw new Exception('"'.$this->path.'" template is not readable or not found');
}
@@ -177,35 +176,4 @@ class Template extends View
return \str_replace([' ', '_'], '-', \strtolower(\preg_replace('/([a-zA-Z])(?=[A-Z])/', '$1-', $input)));
}
/**
* setHtml
*
* Set the Raw html used by this template
*
* @return string
*
*/
public function setHtml(string $html): self
{
$this->html = $html;
return $this;
}
/**
* getHtml
*
* Get the Raw html that this template holds.
*
* @return string
*
*/
public function getHtml(): string
{
if (\is_readable($this->path)) {
return \file_get_contents($this->path);
}
return $this->html;
}
}
+4 -4
View File
@@ -97,8 +97,8 @@ trait LocaleBase
$this->assertEquals($response['headers']['status-code'], 200);
$this->assertEquals(27, $response['body']['sum']);
$this->assertIsArray($response['body']['countries']);
$this->assertEquals($response['body']['countries'][0]['name'], 'Austria');
$this->assertEquals($response['body']['countries'][0]['code'], 'AT');
$this->assertEquals($response['body']['countries'][0]['name'], 'Alemania');
$this->assertEquals($response['body']['countries'][0]['code'], 'DE');
/**
@@ -159,8 +159,8 @@ trait LocaleBase
$this->assertEquals($response['headers']['status-code'], 200);
$this->assertEquals(7, $response['body']['sum']);
$this->assertIsArray($response['body']['continents']);
$this->assertEquals($response['body']['continents'][4]['code'], 'NA');
$this->assertEquals($response['body']['continents'][4]['name'], 'América del Norte');
$this->assertEquals($response['body']['continents'][0]['code'], 'NA');
$this->assertEquals($response['body']['continents'][0]['name'], 'América del Norte');
/**