Merge pull request #6090 from zeroadam/TextToL10n

Split functions to L10n
This commit is contained in:
Hypolite Petovan 2018-11-06 13:44:30 -05:00 committed by GitHub
commit dc669fa736
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 80 additions and 75 deletions

View file

@ -451,7 +451,7 @@ function list_post_dates($uid, $wall)
$dend = substr($dnow, 0, 8) . Temporal::getDaysInMonth(intval($dnow), intval(substr($dnow, 5))); $dend = substr($dnow, 0, 8) . Temporal::getDaysInMonth(intval($dnow), intval(substr($dnow, 5)));
$start_month = DateTimeFormat::utc($dstart, 'Y-m-d'); $start_month = DateTimeFormat::utc($dstart, 'Y-m-d');
$end_month = DateTimeFormat::utc($dend, 'Y-m-d'); $end_month = DateTimeFormat::utc($dend, 'Y-m-d');
$str = day_translate(DateTimeFormat::utc($dnow, 'F')); $str = L10n::getDay(DateTimeFormat::utc($dnow, 'F'));
if (empty($ret[$dyear])) { if (empty($ret[$dyear])) {
$ret[$dyear] = []; $ret[$dyear] = [];

View file

@ -348,65 +348,6 @@ function valid_email($email_address)
return preg_match('/^[_a-zA-Z0-9\-\+]+(\.[_a-zA-Z0-9\-\+]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/', $email_address); return preg_match('/^[_a-zA-Z0-9\-\+]+(\.[_a-zA-Z0-9\-\+]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/', $email_address);
} }
/**
* Load poke verbs
*
* @return array index is present tense verb
* value is array containing past tense verb, translation of present, translation of past
* @hook poke_verbs pokes array
*/
function get_poke_verbs() {
// index is present tense verb
// value is array containing past tense verb, translation of present, translation of past
$arr = [
'poke' => ['poked', L10n::t('poke'), L10n::t('poked')],
'ping' => ['pinged', L10n::t('ping'), L10n::t('pinged')],
'prod' => ['prodded', L10n::t('prod'), L10n::t('prodded')],
'slap' => ['slapped', L10n::t('slap'), L10n::t('slapped')],
'finger' => ['fingered', L10n::t('finger'), L10n::t('fingered')],
'rebuff' => ['rebuffed', L10n::t('rebuff'), L10n::t('rebuffed')],
];
Addon::callHooks('poke_verbs', $arr);
return $arr;
}
/**
* @brief Translate days and months names.
*
* @param string $s String with day or month name.
* @return string Translated string.
*/
function day_translate($s) {
$ret = str_replace(['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],
[L10n::t('Monday'), L10n::t('Tuesday'), L10n::t('Wednesday'), L10n::t('Thursday'), L10n::t('Friday'), L10n::t('Saturday'), L10n::t('Sunday')],
$s);
$ret = str_replace(['January','February','March','April','May','June','July','August','September','October','November','December'],
[L10n::t('January'), L10n::t('February'), L10n::t('March'), L10n::t('April'), L10n::t('May'), L10n::t('June'), L10n::t('July'), L10n::t('August'), L10n::t('September'), L10n::t('October'), L10n::t('November'), L10n::t('December')],
$ret);
return $ret;
}
/**
* @brief Translate short days and months names.
*
* @param string $s String with short day or month name.
* @return string Translated string.
*/
function day_short_translate($s) {
$ret = str_replace(['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
[L10n::t('Mon'), L10n::t('Tue'), L10n::t('Wed'), L10n::t('Thu'), L10n::t('Fri'), L10n::t('Sat'), L10n::t('Sun')],
$s);
$ret = str_replace(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov','Dec'],
[L10n::t('Jan'), L10n::t('Feb'), L10n::t('Mar'), L10n::t('Apr'), L10n::t('May'), ('Jun'), L10n::t('Jul'), L10n::t('Aug'), L10n::t('Sep'), L10n::t('Oct'), L10n::t('Nov'), L10n::t('Dec')],
$ret);
return $ret;
}
/** /**
* Normalize url * Normalize url
* *

View file

@ -40,7 +40,7 @@ function poke_init(App $a)
$verb = notags(trim($_GET['verb'])); $verb = notags(trim($_GET['verb']));
$verbs = get_poke_verbs(); $verbs = L10n::getPokeVerbs();
if (!array_key_exists($verb, $verbs)) { if (!array_key_exists($verb, $verbs)) {
return; return;
@ -171,7 +171,7 @@ function poke_content(App $a)
$parent = (x($_GET,'parent') ? intval($_GET['parent']) : '0'); $parent = (x($_GET,'parent') ? intval($_GET['parent']) : '0');
$verbs = get_poke_verbs(); $verbs = L10n::getPokeVerbs();
$shortlist = []; $shortlist = [];
foreach ($verbs as $k => $v) { foreach ($verbs as $k => $v) {

View file

@ -6,6 +6,7 @@ namespace Friendica\Core;
use Friendica\BaseObject; use Friendica\BaseObject;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Core\Addon;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\System; use Friendica\Core\System;
@ -345,4 +346,67 @@ class L10n extends BaseObject
} }
return $langs; return $langs;
} }
/**
* @brief Translate days and months names.
*
* @param string $s String with day or month name.
* @return string Translated string.
*/
public static function getDay($s)
{
$ret = str_replace(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
[self::t('Monday'), self::t('Tuesday'), self::t('Wednesday'), self::t('Thursday'), self::t('Friday'), self::t('Saturday'), self::t('Sunday')],
$s);
$ret = str_replace(['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
[self::t('January'), self::t('February'), self::t('March'), self::t('April'), self::t('May'), self::t('June'), self::t('July'), self::t('August'), self::t('September'), self::t('October'), self::t('November'), self::t('December')],
$ret);
return $ret;
}
/**
* @brief Translate short days and months names.
*
* @param string $s String with short day or month name.
* @return string Translated string.
*/
public static function getDayShort($s)
{
$ret = str_replace(['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
[self::t('Mon'), self::t('Tue'), self::t('Wed'), self::t('Thu'), self::t('Fri'), self::t('Sat'), self::t('Sun')],
$s);
$ret = str_replace(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
[self::t('Jan'), self::t('Feb'), self::t('Mar'), self::t('Apr'), self::t('May'), ('Jun'), self::t('Jul'), self::t('Aug'), self::t('Sep'), self::t('Oct'), self::t('Nov'), self::t('Dec')],
$ret);
return $ret;
}
/**
* Load poke verbs
*
* @return array index is present tense verb
* value is array containing past tense verb, translation of present, translation of past
* @hook poke_verbs pokes array
*/
public static function getPokeVerbs()
{
// index is present tense verb
// value is array containing past tense verb, translation of present, translation of past
$arr = [
'poke' => ['poked', self::t('poke'), self::t('poked')],
'ping' => ['pinged', self::t('ping'), self::t('pinged')],
'prod' => ['prodded', self::t('prod'), self::t('prodded')],
'slap' => ['slapped', self::t('slap'), self::t('slapped')],
'finger' => ['fingered', self::t('finger'), self::t('fingered')],
'rebuff' => ['rebuffed', self::t('rebuff'), self::t('rebuffed')],
];
Addon::callHooks('poke_verbs', $arr);
return $arr;
}
} }

View file

@ -37,13 +37,13 @@ class Event extends BaseObject
$bd_format = L10n::t('l F d, Y \@ g:i A'); // Friday January 18, 2011 @ 8 AM. $bd_format = L10n::t('l F d, Y \@ g:i A'); // Friday January 18, 2011 @ 8 AM.
$event_start = day_translate( $event_start = L10n::getDay(
!empty($event['adjust']) ? !empty($event['adjust']) ?
DateTimeFormat::local($event['start'], $bd_format) : DateTimeFormat::utc($event['start'], $bd_format) DateTimeFormat::local($event['start'], $bd_format) : DateTimeFormat::utc($event['start'], $bd_format)
); );
if (!empty($event['finish'])) { if (!empty($event['finish'])) {
$event_end = day_translate( $event_end = L10n::getDay(
!empty($event['adjust']) ? !empty($event['adjust']) ?
DateTimeFormat::local($event['finish'], $bd_format) : DateTimeFormat::utc($event['finish'], $bd_format) DateTimeFormat::local($event['finish'], $bd_format) : DateTimeFormat::utc($event['finish'], $bd_format)
); );
@ -564,7 +564,7 @@ class Event extends BaseObject
$start = $event['adjust'] ? DateTimeFormat::local($event['start'], 'c') : DateTimeFormat::utc($event['start'], 'c'); $start = $event['adjust'] ? DateTimeFormat::local($event['start'], 'c') : DateTimeFormat::utc($event['start'], 'c');
$j = $event['adjust'] ? DateTimeFormat::local($event['start'], 'j') : DateTimeFormat::utc($event['start'], 'j'); $j = $event['adjust'] ? DateTimeFormat::local($event['start'], 'j') : DateTimeFormat::utc($event['start'], 'j');
$day = $event['adjust'] ? DateTimeFormat::local($event['start'], $fmt) : DateTimeFormat::utc($event['start'], $fmt); $day = $event['adjust'] ? DateTimeFormat::local($event['start'], $fmt) : DateTimeFormat::utc($event['start'], $fmt);
$day = day_translate($day); $day = L10n::getDay($day);
if ($event['nofinish']) { if ($event['nofinish']) {
$end = null; $end = null;
@ -841,14 +841,14 @@ class Event extends BaseObject
$tformat = L10n::t('g:i A'); // 8:01 AM. $tformat = L10n::t('g:i A'); // 8:01 AM.
// Convert the time to different formats. // Convert the time to different formats.
$dtstart_dt = day_translate( $dtstart_dt = L10n::getDay(
$item['event-adjust'] ? $item['event-adjust'] ?
DateTimeFormat::local($item['event-start'], $dformat) DateTimeFormat::local($item['event-start'], $dformat)
: DateTimeFormat::utc($item['event-start'], $dformat) : DateTimeFormat::utc($item['event-start'], $dformat)
); );
$dtstart_title = DateTimeFormat::utc($item['event-start'], $item['event-adjust'] ? DateTimeFormat::ATOM : 'Y-m-d\TH:i:s'); $dtstart_title = DateTimeFormat::utc($item['event-start'], $item['event-adjust'] ? DateTimeFormat::ATOM : 'Y-m-d\TH:i:s');
// Format: Jan till Dec. // Format: Jan till Dec.
$month_short = day_short_translate( $month_short = L10n::getDayShort(
$item['event-adjust'] ? $item['event-adjust'] ?
DateTimeFormat::local($item['event-start'], 'M') DateTimeFormat::local($item['event-start'], 'M')
: DateTimeFormat::utc($item['event-start'], 'M') : DateTimeFormat::utc($item['event-start'], 'M')
@ -860,7 +860,7 @@ class Event extends BaseObject
$start_time = $item['event-adjust'] ? $start_time = $item['event-adjust'] ?
DateTimeFormat::local($item['event-start'], $tformat) DateTimeFormat::local($item['event-start'], $tformat)
: DateTimeFormat::utc($item['event-start'], $tformat); : DateTimeFormat::utc($item['event-start'], $tformat);
$start_short = day_short_translate( $start_short = L10n::getDayShort(
$item['event-adjust'] ? $item['event-adjust'] ?
DateTimeFormat::local($item['event-start'], $dformat_short) DateTimeFormat::local($item['event-start'], $dformat_short)
: DateTimeFormat::utc($item['event-start'], $dformat_short) : DateTimeFormat::utc($item['event-start'], $dformat_short)
@ -869,13 +869,13 @@ class Event extends BaseObject
// If the option 'nofinisch' isn't set, we need to format the finish date/time. // If the option 'nofinisch' isn't set, we need to format the finish date/time.
if (!$item['event-nofinish']) { if (!$item['event-nofinish']) {
$finish = true; $finish = true;
$dtend_dt = day_translate( $dtend_dt = L10n::getDay(
$item['event-adjust'] ? $item['event-adjust'] ?
DateTimeFormat::local($item['event-finish'], $dformat) DateTimeFormat::local($item['event-finish'], $dformat)
: DateTimeFormat::utc($item['event-finish'], $dformat) : DateTimeFormat::utc($item['event-finish'], $dformat)
); );
$dtend_title = DateTimeFormat::utc($item['event-finish'], $item['event-adjust'] ? DateTimeFormat::ATOM : 'Y-m-d\TH:i:s'); $dtend_title = DateTimeFormat::utc($item['event-finish'], $item['event-adjust'] ? DateTimeFormat::ATOM : 'Y-m-d\TH:i:s');
$end_short = day_short_translate( $end_short = L10n::getDayShort(
$item['event-adjust'] ? $item['event-adjust'] ?
DateTimeFormat::local($item['event-finish'], $dformat_short) DateTimeFormat::local($item['event-finish'], $dformat_short)
: DateTimeFormat::utc($item['event-finish'], $dformat_short) : DateTimeFormat::utc($item['event-finish'], $dformat_short)

View file

@ -617,7 +617,7 @@ class Profile
$rr['link'] = Contact::magicLink($rr['url']); $rr['link'] = Contact::magicLink($rr['url']);
$rr['title'] = $rr['name']; $rr['title'] = $rr['name'];
$rr['date'] = day_translate(DateTimeFormat::convert($rr['start'], $a->timezone, 'UTC', $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . L10n::t('[today]') : ''); $rr['date'] = L10n::getDay(DateTimeFormat::convert($rr['start'], $a->timezone, 'UTC', $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . L10n::t('[today]') : '');
$rr['startime'] = null; $rr['startime'] = null;
$rr['today'] = $today; $rr['today'] = $today;
} }
@ -703,7 +703,7 @@ class Profile
$rr['title'] = $title; $rr['title'] = $title;
$rr['description'] = $description; $rr['description'] = $description;
$rr['date'] = day_translate(DateTimeFormat::convert($rr['start'], $rr['adjust'] ? $a->timezone : 'UTC', 'UTC', $bd_format)) . (($today) ? ' ' . L10n::t('[today]') : ''); $rr['date'] = L10n::getDay(DateTimeFormat::convert($rr['start'], $rr['adjust'] ? $a->timezone : 'UTC', 'UTC', $bd_format)) . (($today) ? ' ' . L10n::t('[today]') : '');
$rr['startime'] = $strt; $rr['startime'] = $strt;
$rr['today'] = $today; $rr['today'] = $today;
@ -752,7 +752,7 @@ class Profile
$year_bd_format = L10n::t('j F, Y'); $year_bd_format = L10n::t('j F, Y');
$short_bd_format = L10n::t('j F'); $short_bd_format = L10n::t('j F');
$val = day_translate( $val = L10n::getDay(
intval($a->profile['dob']) ? intval($a->profile['dob']) ?
DateTimeFormat::utc($a->profile['dob'] . ' 00:00 +00:00', $year_bd_format) DateTimeFormat::utc($a->profile['dob'] . ' 00:00 +00:00', $year_bd_format)
: DateTimeFormat::utc('2001-' . substr($a->profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format) : DateTimeFormat::utc('2001-' . substr($a->profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format)

View file

@ -463,11 +463,11 @@ class Temporal
$tddate = intval(DateTimeFormat::localNow('j')); $tddate = intval(DateTimeFormat::localNow('j'));
} }
$str_month = day_translate($mtab[$m]); $str_month = L10n::getDay($mtab[$m]);
$o = '<table class="calendar' . $class . '">'; $o = '<table class="calendar' . $class . '">';
$o .= "<caption>$str_month $y</caption><tr>"; $o .= "<caption>$str_month $y</caption><tr>";
for ($a = 0; $a < 7; $a ++) { for ($a = 0; $a < 7; $a ++) {
$o .= '<th>' . mb_substr(day_translate($dn[$a]), 0, 3, 'UTF-8') . '</th>'; $o .= '<th>' . mb_substr(L10n::getDay($dn[$a]), 0, 3, 'UTF-8') . '</th>';
} }
$o .= '</tr><tr>'; $o .= '</tr><tr>';