Skip to content

Commit

Permalink
Added i18n support (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasLang50 authored Nov 20, 2020
1 parent 02e84d7 commit 19eb60b
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 26 deletions.
40 changes: 40 additions & 0 deletions lang/de.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
de:
JonoM\BetterNavigator:
VIEWING_LIVE: 'Live'
VIEWING_DRAFT: 'Entwurf'
VIEWING_ARCHIVED: 'Archiviert'

DEVELOPER_TOOLS_HEADING: 'Entwickler Tools'
DEBUGGING_HEADING: 'Debugging'

RESTORE_LABEL: 'Wiederherstellen'
VIEW_LIVE_LABEL: 'Live ansehen'
NOT_YET_PUBLISHED_LABEL: 'Noch nicht veröffentlicht'
VIEW_DRAFT_LABEL: 'Entwurf ansehen'
DELETED_FROM_DRAFT_SITE_LABEL: 'Aus dem Entwurf gelöscht'
EDIT_IN_CMS_LABEL: 'Im CMS bearbeiten'
LOG_OUT_LABEL: 'Ausloggen'
LOG_IN_LABEL: 'Einloggen'
DEV_MOVE_ON_LABEL: 'Dev Modus aktiviert'
DEV_MODE_LABEL: 'Dev Modus'
FLUSH_CACHE_LABEL: 'Caches leeren'
BUILD_DATABASE_LABEL: 'Datenbank generieren'
DEV_MENU_LABEL: 'Dev Menü'
SHOW_TEMPLATE_LABEL: 'Template anzeigen'
SHOW_METRICS_LABEL: 'Metrics anzeigen'
DEBUG_PAGE_LABEL: 'Seite debuggen'
DEBUG_REQUEST_LABEL: 'Request debuggen'
DEBUG_FAILOVER_LABEL: 'Debug Failover'
SHOW_QUERIES_LABEL: 'Queries anzeigen'
PREVIEW_WRITE_LABEL: 'Queryvorschau'

END_DEV_MODE_TITLE: 'Ausloggen um den Dev Modus zu beenden'
FLUSH_CACHE_TITLE: 'Templates + Manifest neu einlesen und Bilder für diese Seite generieren (Verhalten kann sich je nach Framework-Version unterscheiden)'
BUILD_DATABASE_TITLE: 'Datenbank generieren und die Caches leeren (Template-Caches vor SS-3.1.7 sind ausgeschlossen)'
SHOW_TEMPLATE_TITLE: 'Zeigt die kompilierte Version von allen benutzten Templates mit Zeilenangaben an. Gut geeignet, wenn Syntax-Fehler in einem Template vorhanden sind. Kann auf einer Live-Seite ohne isDev nicht benutzt werden'
EXEC_METRIC_TITLE: 'Zeigt die vergangene Zeit zum Ausführen und die Spitzenauslastung der Speichernutzung für diesen Request an'
DEBUG_PAGE_TITLE: 'Zeigt eine Sammlung an Debugging-informationen über die Director- / Controller-operationen'
DEBUG_REQUEST_TITLE: 'Listet alle Schritte des Requests vom ursprünglichen HTTPRequest bis hin zum Controller und dem Template-Rendering auf'
DEBUG_FAILOVER_TITLE: 'Zeigt die Failover Methoden von vererbten Klassen an'
SHOW_QUERIES_TITLE: 'Listet alle ausgeführten SQL queries auf'
PREVIEW_WRITE_TITLE: "Listet alle Insert / Update SQL Queries auf, führt sie aber nicht aus. Als Vorschau für Änderungen in der Datenbank nützlich"
40 changes: 40 additions & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
en:
JonoM\BetterNavigator:
VIEWING_LIVE: 'Live'
VIEWING_DRAFT: 'Draft'
VIEWING_ARCHIVED: 'Archived'

DEVELOPER_TOOLS_HEADING: 'Developer tools'
DEBUGGING_HEADING: 'Debugging'

RESTORE_LABEL: 'Restore'
VIEW_LIVE_LABEL: 'View live'
NOT_YET_PUBLISHED_LABEL: 'Not yet published'
VIEW_DRAFT_LABEL: 'View draft'
DELETED_FROM_DRAFT_SITE_LABEL: 'Deleted from draft site'
EDIT_IN_CMS_LABEL: 'Edit in CMS'
LOG_OUT_LABEL: 'Log out'
LOG_IN_LABEL: 'Log in'
DEV_MOVE_ON_LABEL: 'Dev mode on'
DEV_MODE_LABEL: 'Dev mode'
FLUSH_CACHE_LABEL: 'Flush caches'
BUILD_DATABASE_LABEL: 'Build database'
DEV_MENU_LABEL: 'Dev menu'
SHOW_TEMPLATE_LABEL: 'Show template'
SHOW_METRICS_LABEL: 'Show metrics'
DEBUG_PAGE_LABEL: 'Debug page'
DEBUG_REQUEST_LABEL: 'Debug request'
DEBUG_FAILOVER_LABEL: 'Debug failover'
SHOW_QUERIES_LABEL: 'Show queries'
PREVIEW_WRITE_LABEL: 'Preview write'

END_DEV_MODE_TITLE: 'Log out to end Dev Mode'
FLUSH_CACHE_TITLE: 'Flush templates and manifest, and regenerate images for this page (behaviour varies by Framework version)'
BUILD_DATABASE_TITLE: 'Build database and flush caches (excludes template caches pre SS-3.1.7)'
SHOW_TEMPLATE_TITLE: 'Show the compiled version of all the templates used, including line numbers. Good when you have a syntax error in a template. Cannot be used on a Live site without isDev'
EXEC_METRIC_TITLE: 'Display the execution time and peak memory usage for the request'
DEBUG_PAGE_TITLE: 'Show a collection of debugging information about the director / controller operation'
DEBUG_REQUEST_TITLE: 'Show all steps of the request from initial HTTPRequest to Controller to Template Rendering'
DEBUG_FAILOVER_TITLE: 'Shows failover methods from classes extended'
SHOW_QUERIES_TITLE: 'List all SQL queries executed'
PREVIEW_WRITE_TITLE: "List all insert / update SQL queries, and don't execute them. Useful for previewing writes to the database"
17 changes: 14 additions & 3 deletions src/Extension/BetterNavigatorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private function generateNavigator()
// Get SilverStripeNavigator links & stage info (CMS/Stage/Live/Archive)
$nav = [];
$viewing = '';
$viewingTitle = '';
$navigator = SilverStripeNavigator::create($this->owner->dataRecord);
$isDev = Director::isDev();

Expand All @@ -96,9 +97,18 @@ private function generateNavigator()
'Active' => $active
];
if ($active) {
if ($name == 'LiveLink') $viewing = 'Live';
if ($name == 'StageLink') $viewing = 'Draft';
if ($name == 'ArchiveLink') $viewing = 'Archived';
if ($name == 'LiveLink') {
$viewing = 'Live';
$viewingTitle = _t('JonoM\BetterNavigator.VIEWING_LIVE', 'Live');
}
else if ($name == 'StageLink') {
$viewing = 'Draft';
$viewingTitle = _t('JonoM\BetterNavigator.VIEWING_DRAFT', 'Draft');
}
else if ($name == 'ArchiveLink') {
$viewing = 'Archived';
$viewingTitle = _t('JonoM\BetterNavigator.VIEWING_ARCHIVED', 'Archived');
}
}
}
// Only show edit link if user has permission to edit this page
Expand All @@ -121,6 +131,7 @@ private function generateNavigator()
'Member' => $member,
'Stage' => Versioned::get_stage(),
'Viewing' => $viewing, // What we're viewing doesn't necessarily align with the active Stage
'ViewingTitle' => $viewingTitle,
'LoginLink' => Controller::join_links(Director::absoluteBaseURL(), Security::config()->login_url, $backURL),
'LogoutLink' => Controller::join_links(Director::absoluteBaseURL() . Security::config()->logout_url, $backURL),
'LogoutForm' => $logoutForm,
Expand Down
95 changes: 72 additions & 23 deletions templates/BetterNavigator/BetterNavigator.ss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div id="BetterNavigatorStatus" class="$Viewing">
<span class="bn-icon-cog"></span>
$Viewing
$ViewingTitle
<span class="bn-icon-close"></span>
</div>

Expand All @@ -11,30 +11,30 @@
<div class="bn-links">

<% if $ArchiveLink.Active %>
<% if $EditLink %><a href="$EditLink" target="_blank"><span class="bn-icon-edit"></span>Restore</a><% end_if %>
<% if $EditLink %><a href="$EditLink" target="_blank"><span class="bn-icon-edit"></span><%t JonoM\BetterNavigator.RESTORE_LABEL 'Restore' %></a><% end_if %>
<% else %>
<% if not $LiveLink.Active %>
<% if $LiveLink.Link %>
<a href="$LiveLink.Link"><span class="bn-icon-view"></span>View live</a>
<a href="$LiveLink.Link"><span class="bn-icon-view"></span><%t JonoM\BetterNavigator.VIEW_LIVE_LABEL 'View live' %></a>
<% else %>
<span class="bn-disabled"><span class="bn-icon-view"></span>Not yet published</span>
<span class="bn-disabled"><span class="bn-icon-view"></span><%t JonoM\BetterNavigator.NOT_YET_PUBLISHED_LABEL 'Not yet published' %></span>
<% end_if %>
<% end_if %>
<% if not $StageLink.Active %>
<% if $StageLink.Link %>
<a href="$StageLink.Link"><span class="bn-icon-view"></span>View draft</a>
<a href="$StageLink.Link"><span class="bn-icon-view"></span><%t JonoM\BetterNavigator.VIEW_DRAFT_LABEL 'View draft' %></a>
<% else %>
<span class="bn-disabled"><span class="bn-icon-view"></span>Deleted from draft site</span>
<span class="bn-disabled"><span class="bn-icon-view"></span><%t JonoM\BetterNavigator.DELETED_FROM_DRAFT_SITE_LABEL 'Deleted from draft site' %></span>
<% end_if %>
<% end_if %>
<% if $EditLink %><a href="$EditLink" target="_blank"><span class="bn-icon-edit"></span>Edit in CMS</a><% end_if %>
<% if $EditLink %><a href="$EditLink" target="_blank"><span class="bn-icon-edit"></span><%t JonoM\BetterNavigator.EDIT_IN_CMS_LABEL 'Edit in CMS' %></a><% end_if %>
<% end_if %>

<% if $Member %>
$LogoutForm
<a href="$LogoutLink" id="BetterNavigatorLogoutLink"><span class="bn-icon-user"></span>Log out<% if $Member.FirstName %><span class="light"> ($Member.FirstName)</span><% end_if %></a>
<a href="$LogoutLink" id="BetterNavigatorLogoutLink"><span class="bn-icon-user"></span><%t JonoM\BetterNavigator.LOG_OUT_LABEL 'Log out' %><% if $Member.FirstName %><span class="light"> ($Member.FirstName)</span><% end_if %></a>
<% else %>
<a href="$LoginLink"><span class="bn-icon-user"></span>Log in</a>
<a href="$LoginLink"><span class="bn-icon-user"></span><%t JonoM\BetterNavigator.LOG_IN_LABEL 'Log in' %></a>
<% end_if %>

</div>
Expand All @@ -43,19 +43,33 @@

<% if $Mode=='dev' || $IsDeveloper %>

<div class="bn-heading">Developer tools</div>
<div class="bn-heading"><%t JonoM\BetterNavigator.DEVELOPER_TOOLS_HEADING 'Developer tools' %></div>

<div class="bn-links">

<% if $Mode='dev' %>
<span class="bn-disabled" title="Log out to end Dev Mode"><span class="bn-icon-tick"></span>Dev mode on</span>
<span class="bn-disabled" title="<%t JonoM\BetterNavigator.END_DEV_MODE_TITLE 'Log out to end Dev Mode' %>">
<span class="bn-icon-tick"></span>
<%t JonoM\BetterNavigator.DEV_MOVE_ON_LABEL 'Dev mode on' %>
</span>
<% else %>
<a href="{$AbsoluteLink}?isDev=1"><span class="bn-icon-devmode"></span>Dev mode</a>
<a href="{$AbsoluteLink}?isDev=1"><span class="bn-icon-devmode"></span><%t JonoM\BetterNavigator.DEV_MODE_LABEL 'Dev mode' %></a>
<% end_if %>

<a href="{$AbsoluteLink}?flush=1" title="Flush templates and manifest, and regenerate images for this page (behaviour varies by Framework version)"><span class="bn-icon-flush"></span>Flush caches</a>
<a href="{$AbsoluteBaseURL}dev/build/?flush=1" target="_blank" title="Build database and flush caches (excludes template caches pre SS-3.1.7)"><span class="bn-icon-db"></span>Build database</a>
<a href="{$AbsoluteBaseURL}dev/" target="_blank"><span class="bn-icon-tools"></span>Dev menu</a>
<a href="{$AbsoluteLink}?flush=1"
title="<%t JonoM\BetterNavigator.FLUSH_CACHE_TITLE 'Flush templates and manifest, and regenerate images for this page (behaviour varies by Framework version)' %>"
>
<span class="bn-icon-flush"></span>
<%t JonoM\BetterNavigator.FLUSH_CACHE_LABEL 'Flush caches' %>
</a>
<a href="{$AbsoluteBaseURL}dev/build/?flush=1"
target="_blank"
title="<%t JonoM\BetterNavigator.BUILD_DATABASE_TITLE 'Build database and flush caches (excludes template caches pre SS-3.1.7)' %>"
>
<span class="bn-icon-db"></span>
<%t JonoM\BetterNavigator.BUILD_DATABASE_LABEL 'Build database' %>
</a>
<a href="{$AbsoluteBaseURL}dev/" target="_blank"><span class="bn-icon-tools"></span><%t JonoM\BetterNavigator.DEV_MENU_LABEL 'Dev menu' %></a>

</div>

Expand All @@ -65,17 +79,52 @@

<% if $Mode=='dev' %>

<div class="bn-heading">Debugging</div>
<div class="bn-heading"><%t JonoM\BetterNavigator.DEBUGGING_HEADING 'Debugging' %></div>

<div class="bn-links">

<a href="{$AbsoluteLink}?showtemplate=1"><span class="bn-icon-info"></span>Show template</a>
<a href="{$AbsoluteLink}?execmetric=1"><span class="bn-icon-info"></span>Show metrics</a>
<a href="{$AbsoluteLink}?debug=1"><span class="bn-icon-info"></span>Debug page</a>
<a href="{$AbsoluteLink}?debug_request=1"><span class="bn-icon-info"></span>Debug request</a>
<a href="{$AbsoluteLink}?debugfailover=1"><span class="bn-icon-info"></span>Debug failover</a>
<a href="{$AbsoluteLink}?showqueries=1"><span class="bn-icon-info"></span>Show queries</a>
<a href="{$AbsoluteLink}?previewwrite=1"><span class="bn-icon-info"></span>Preview write</a>
<a href="{$AbsoluteLink}?showtemplate=1"
title="<%t JonoM\BetterNavigator.SHOW_TEMPLATE_TITLE 'Show the compiled version of all the templates used, including line numbers. Good when you have a syntax error in a template. Cannot be used on a Live site without isDev' %>"
>
<span class="bn-icon-info"></span>
<%t JonoM\BetterNavigator.SHOW_TEMPLATE_LABEL 'Show template' %>
</a>
<a href="{$AbsoluteLink}?execmetric=1"
title="<%t JonoM\BetterNavigator.EXEC_METRIC_TITLE 'Display the execution time and peak memory usage for the request' %>"
>
<span class="bn-icon-info"></span>
<%t JonoM\BetterNavigator.SHOW_METRICS_LABEL 'Show metrics' %>
</a>
<a href="{$AbsoluteLink}?debug=1"
title="<%t JonoM\BetterNavigator.DEBUG_PAGE_TITLE 'Show a collection of debugging information about the director / controller operation' %>"
>
<span class="bn-icon-info"></span>
<%t JonoM\BetterNavigator.DEBUG_PAGE_LABEL 'Debug page' %>
</a>
<a href="{$AbsoluteLink}?debug_request=1"
title="<%t JonoM\BetterNavigator.DEBUG_REQUEST_TITLE 'Show all steps of the request from initial HTTPRequest to Controller to Template Rendering' %>"
>
<span class="bn-icon-info"></span>
<%t JonoM\BetterNavigator.DEBUG_REQUEST_LABEL 'Debug request' %>
</a>
<a href="{$AbsoluteLink}?debugfailover=1"
title="<%t JonoM\BetterNavigator.DEBUG_FAILOVER_TITLE 'Shows failover methods from classes extended' %>"
>
<span class="bn-icon-info"></span>
<%t JonoM\BetterNavigator.DEBUG_FAILOVER_LABEL 'Debug failover' %>
</a>
<a href="{$AbsoluteLink}?showqueries=1"
title="<%t JonoM\BetterNavigator.SHOW_QUERIES_TITLE 'List all SQL queries executed' %>"
>
<span class="bn-icon-info"></span>
<%t JonoM\BetterNavigator.SHOW_QUERIES_LABEL 'Show queries' %>
</a>
<a href="{$AbsoluteLink}?previewwrite=1"
title="<%t JonoM\BetterNavigator.PREVIEW_WRITE_TITLE "List all insert / update SQL queries, and don't execute them. Useful for previewing writes to the database" %>"
>
<span class="bn-icon-info"></span>
<%t JonoM\BetterNavigator.PREVIEW_WRITE_LABEL 'Preview write' %>
</a>

</div>

Expand Down

0 comments on commit 19eb60b

Please sign in to comment.