Skip to content

Commit

Permalink
Allow translating strings on landing page
Browse files Browse the repository at this point in the history
  • Loading branch information
addshore committed Apr 27, 2016
1 parent f6d2511 commit 286d2b9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.html → index.base.html
Expand Up @@ -66,7 +66,7 @@ <h2>Lizenzhinweise für Bilder aus Wikipedia und Wikimedia Commons</h2>
</div>

<form id="file-form" onsubmit="return false;">
<input id="file-form-input" type="text" inputmode="url" name="file" placeholder="Internetadresse eines Wikimedia-Commons-Bildes oder eines Wikipedia-Artikels" autofocus><button type="submit" class="green-btn">Los!</button>
<input id="file-form-input" type="text" inputmode="url" name="file" placeholder="Internetadresse eines Wikimedia-Commons-Bildes oder eines Wikipedia-Artikels" autofocus><button type="submit" class="green-btn">i18n.index.gobutton</button>
<div class="container-fluid display-none" id="file-form-alert">
<span class="glyphicon glyphicon-warning-sign"></span><span id="file-form-alert-placeholder">Alert</span>
</div>
Expand Down
22 changes: 22 additions & 0 deletions index.php
@@ -0,0 +1,22 @@
<?php

// Get the language, fallback to de if none is passed
$lang = isset( $_GET['lang'] ) ? $_GET['lang'] : 'de';

// Load the i18n file
$i18nData = file_get_contents(__DIR__ . '/js/i18n.json');
$i18nData = json_decode($i18nData, true);
$i18nData = isset( $i18nData[$lang] ) ? $i18nData[$lang] : null;

// Get the base html to output
$html = file_get_contents( __DIR__ . '/index.base.html' );

// If we have any i18n data replace the i18n codes with new strings
if ( $i18nData && isset( $i18nData['index'] ) ) {
foreach( $i18nData['index'] as $key => $string ) {
$html = str_replace( 'i18n.index.' . $key, $string, $html );
}
}

// Output the html
echo $html;
3 changes: 3 additions & 0 deletions js/i18n.json
@@ -1,5 +1,8 @@
{
"de": {
"index": {
"gobutton": "Los!"
},
"error": {
"generic": "Ein unvorhergesehener Fehler ist aufgetreten.",
"mediatype-unsupported": "Der Medientyp der angegebenen Datei wird von dieser Applikation momentan leider nicht unterstützt.",
Expand Down

0 comments on commit 286d2b9

Please sign in to comment.