Skip to content

Commit

Permalink
Internationalization #136
Browse files Browse the repository at this point in the history
  • Loading branch information
abrain committed Feb 9, 2021
1 parent ba44bd5 commit ca2cf2f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
41 changes: 23 additions & 18 deletions src/Widgets/RecentIncidents.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use function array_merge;
use function checked;
use function esc_html;
use function esc_html__;
use function get_queried_object_id;
use function get_taxonomy;
use function printf;
Expand Down Expand Up @@ -40,16 +41,16 @@ public function __construct(Formatter $formatter)
{
parent::__construct(
'einsatzverwaltung_widget',
'Letzte Einsätze',
__('Recent Incident Reports', 'einsatzverwaltung'),
[
'description' => 'Zeigt die neuesten Einsätze an.',
'description' => __('The the most recent Incident Reports.', 'einsatzverwaltung'),
'customize_selective_refresh' => true,
]
);
$this->formatter = $formatter;

$this->defaults = [
'title' => 'Letzte Einsätze',
'title' => '',
'anzahl' => 3,
'units' => [],
'zeigeDatum' => false,
Expand All @@ -68,7 +69,7 @@ public function __construct(Formatter $formatter)
public function widget($args, $instance)
{
$instance = array_merge($this->defaults, $instance);
$title = empty($instance['title']) ? $this->defaults['title'] : $instance['title'];
$title = empty($instance['title']) ? __('Recent incidents', 'einsatzverwaltung') : $instance['title'];

echo $args['before_widget'];
echo $args['before_title'];
Expand All @@ -81,7 +82,7 @@ public function widget($args, $instance)
printf(
'<p class="einsatzfeed"><span class="fa fa-rss"></span>&nbsp;<a href="%s">%s</a></p>',
get_post_type_archive_feed_link('einsatz'),
'Einsatzberichte (Feed)'
esc_html__('Incident Reports feed', 'einsatzverwaltung')
);
}
echo $args['after_widget'];
Expand All @@ -99,7 +100,7 @@ private function echoReports(array $instance)
$reports = $reportQuery->getReports();

if (empty($reports)) {
echo '<p>Keine Eins&auml;tze</p>';
echo sprintf("<p>%s</p>", esc_html__('No reports', 'einsatzverwaltung'));
return;
}

Expand Down Expand Up @@ -143,7 +144,7 @@ private function echoSingleReport(IncidentReport $report, $instance)
);
if ($instance['zeigeZeit']) {
printf(
' | <span class="einsatzzeit">%s Uhr</span>',
' | <span class="einsatzzeit">%s</span>',
esc_html(date_i18n(get_option('time_format', 'H:i'), $timestamp))
);
}
Expand All @@ -164,7 +165,11 @@ private function echoSingleReport(IncidentReport $report, $instance)
if ($instance['zeigeOrt']) {
$location = $report->getLocation();
if (!empty($location)) {
printf('<br><span class="einsatzort">Ort:&nbsp;%s</span>', $location);
$locationFormat = sprintf(
'<br><span class="einsatzort">%s</span>',
esc_html__('Location: %s', 'einsatzverwaltung')
);
printf($locationFormat, esc_html($location));
}
}
}
Expand Down Expand Up @@ -206,15 +211,15 @@ public function form($instance): string
printf(
'<p><label for="%1$s">%2$s</label><input class="widefat" id="%1$s" name="%3$s" type="text" value="%4$s" /></p>',
$this->get_field_id('title'),
'Titel:',
esc_html__('Title:', 'einsatzverwaltung'),
$this->get_field_name('title'),
esc_attr($instance['title'])
);

printf(
'<p><label for="%1$s">%2$s</label>&nbsp;<input class="tiny-text" id="%1$s" name="%3$s" type="number" min="1" value="%4$s" size="3" /></p>',
$this->get_field_id('anzahl'),
'Anzahl der Einsatzberichte, die angezeigt werden:',
esc_html__('Number of reports to show:', 'einsatzverwaltung'),
$this->get_field_name('anzahl'),
esc_attr($instance['anzahl'])
);
Expand All @@ -228,29 +233,29 @@ public function form($instance): string
);

echo '<p>';
$this->echoCheckbox($instance, 'zeigeFeedlink', 'Link zum Feed anzeigen');
$this->echoCheckbox($instance, 'zeigeFeedlink', __('Show link to RSS feed', 'einsatzverwaltung'));
echo '</p>';

echo '<p><strong>Einsatzdaten:</strong></p>';
echo sprintf("<p><strong>%s</strong></p>", __('Incident details', 'einsatzverwaltung'));

echo '<p>';
$this->echoCheckbox($instance, 'zeigeDatum', 'Datum anzeigen');
$this->echoCheckbox($instance, 'zeigeDatum', __('Show date', 'einsatzverwaltung'));
echo '</p><p style="text-indent:1em;">';
$this->echoCheckbox($instance, 'zeigeZeit', 'Zeit anzeigen (nur in Kombination mit Datum)');
$this->echoCheckbox($instance, 'zeigeZeit', __('Show time', 'einsatzverwaltung'));
echo '</p><p>';
$this->echoCheckbox($instance, 'zeigeArt', 'Einsatzart anzeigen');
$this->echoCheckbox($instance, 'zeigeArt', __('Show Incident Category', 'einsatzverwaltung'));
echo '</p><p style="text-indent:1em;">';
$this->echoCheckbox($instance, 'zeigeArtHierarchie', 'Hierarchie der Einsatzart anzeigen');
$this->echoCheckbox($instance, 'zeigeArtHierarchie', __('Show parent Incident Categories', 'einsatzverwaltung'));
echo '</p><p>';
$this->echoCheckbox($instance, 'zeigeOrt', 'Ort anzeigen');
$this->echoCheckbox($instance, 'zeigeOrt', __('Show location', 'einsatzverwaltung'));
echo '</p>';

printf(
'<p><input id="%1$s" name="%2$s" type="checkbox" value="1" %3$s />&nbsp;<label for="%1$s">%4$s</label></p>',
esc_attr($this->get_field_id('showAnnotations')),
esc_attr($this->get_field_name('showAnnotations')),
checked($instance['showAnnotations'], '1', false),
'Vermerke anzeigen'
esc_html__('Show annotations', 'einsatzverwaltung')
);

return '';
Expand Down
25 changes: 12 additions & 13 deletions src/Widgets/RecentIncidentsFormatted.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
use abrain\Einsatzverwaltung\ReportQuery;
use abrain\Einsatzverwaltung\Types\Unit;
use abrain\Einsatzverwaltung\Util\Formatter;
use function esc_html__;
use function esc_html_e;
use function get_taxonomy;

/**
Expand Down Expand Up @@ -152,9 +154,9 @@ public function __construct(Formatter $formatter)
{
parent::__construct(
'recent-incidents-formatted',
'Letzte Eins&auml;tze (eigenes Format)',
__('Recent Incident Reports (Templates)', 'einsatzverwaltung'),
array(
'description' => 'Zeigt die neuesten Eins&auml;tze an. Das Aussehen kann vollst&auml;ndig mit eigenem HTML bestimmt werden.',
'description' => __('The the most recent Incident Reports. Layout can be customized with HTML and placeholders.', 'einsatzverwaltung'),
'customize_selective_refresh' => true,
)
);
Expand All @@ -170,17 +172,14 @@ public function __construct(Formatter $formatter)
public function widget($args, $instance)
{
$settings = wp_parse_args($instance, $this->defaults);

if (empty($settings['title'])) {
$settings['title'] = 'Letzte Eins&auml;tze';
}
$title = empty($settings['title']) ? __('Recent incidents', 'einsatzverwaltung') : $settings['title'];

if (empty($settings['numIncidents'])) {
$settings['numIncidents'] = $this->defaults['numIncidents'];
}

echo $args['before_widget'];
echo $args['before_title'] . apply_filters('widget_title', $settings['title']) . $args['after_title'];
echo $args['before_title'] . apply_filters('widget_title', $title) . $args['after_title'];

$reportQuery = new ReportQuery();
$reportQuery->setOrderAsc(false);
Expand Down Expand Up @@ -244,7 +243,7 @@ public function form($instance): string
printf(
'<label for="%1$s">%2$s</label><input class="widefat" id="%1$s" name="%3$s" type="text" value="%4$s" />',
$this->get_field_id('title'),
'Titel:',
esc_html__('Title:', 'einsatzverwaltung'),
$this->get_field_name('title'),
esc_attr($values['title'])
);
Expand All @@ -254,7 +253,7 @@ public function form($instance): string
printf(
'<label for="%1$s">%2$s</label>&nbsp;<input id="%1$s" name="%3$s" type="text" value="%4$s" size="3" />',
$this->get_field_id('numIncidents'),
'Anzahl der Einsatzberichte, die angezeigt werden:',
esc_html__('Number of reports to show:', 'einsatzverwaltung'),
$this->get_field_name('numIncidents'),
esc_attr($values['numIncidents'])
);
Expand All @@ -272,7 +271,7 @@ public function form($instance): string
printf(
'<label for="%1$s">%2$s</label><textarea class="widefat" id="%1$s" name="%3$s">%4$s</textarea>',
$this->get_field_id('beforeContent'),
'HTML-Code vor den Einsatzberichten:',
esc_html__('HTML code before the reports:', 'einsatzverwaltung'),
$this->get_field_name('beforeContent'),
esc_textarea($values['beforeContent'])
);
Expand All @@ -282,7 +281,7 @@ public function form($instance): string
printf(
'<label for="%1$s">%2$s</label><textarea class="widefat" id="%1$s" name="%3$s">%4$s</textarea>',
$this->get_field_id('pattern'),
'HTML-Template pro Einsatzbericht:',
esc_html__('HTML template per report:', 'einsatzverwaltung'),
$this->get_field_name('pattern'),
esc_textarea($values['pattern'])
);
Expand All @@ -293,7 +292,7 @@ public function form($instance): string
printf(
'<label for="%1$s">%2$s</label><textarea class="widefat" id="%1$s" name="%3$s">%4$s</textarea>',
$this->get_field_id('afterContent'),
'HTML-Code nach den Einsatzberichten:',
esc_html__('HTML code after the reports:', 'einsatzverwaltung'),
$this->get_field_name('afterContent'),
esc_textarea($values['afterContent'])
);
Expand All @@ -309,7 +308,7 @@ public function form($instance): string
private function printTagReplacementInfo($allowedTags)
{
echo '<br><small>';
_e('The following tags will be replaced:', 'einsatzverwaltung');
esc_html_e('The following tags will be replaced:', 'einsatzverwaltung');
foreach ($allowedTags as $tag) {
printf('<br><strong>%s</strong> (%s)', esc_html($tag), esc_html($this->formatter->getLabelForTag($tag)));
}
Expand Down

0 comments on commit ca2cf2f

Please sign in to comment.