Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Raddit Translator</title>
- <meta charset="utf-8" />
- <style>
- body {
- font-family: sans-serif;
- }
- code {
- padding: 2px;
- background: #eee;
- border: 1px solid #999;
- border-radius: 4px;
- }
- li {
- margin-bottom: 3px;
- }
- table {
- width: 100%;
- }
- th {
- text-align: left;
- }
- a#return, input[type="submit"] {
- text-decoration: none;
- color: #333;
- border: 1px solid #999;
- background: #eeeeee;
- border-radius: 3px;
- padding: 4px;
- margin: 10px 0 0 3px;
- display: inline-block;
- }
- </style>
- </head>
- <body>
- <?php
- include '../libraries/autoload.php';
- use Alchemy\Component\Yaml\Yaml;
- ob_end_flush();
- function getTranslationFile($fileName) {
- $fileName = str_replace('/', '', $fileName);
- return @file_get_contents('https://gitlab.com/edgyemma/Postmill/raw/master/translations/'. $fileName .'.yml');
- }
- function errMsg($title, $message) {
- echo '<h1>'.$title.'</h1>'.PHP_EOL;
- echo '<p>'.$message.'</p>';
- echo '<a href="?" id="return">← Return</a>';
- }
- function readLines($string, callable $handler) {
- $tok = strtok($string, "\r\n");
- while($tok !== false) {
- $handler($tok);
- $tok = strtok("\r\n");
- }
- }
- function readLines2($string) {
- $i = 0;
- $lines = [];
- $tok = strtok($string, "\r\n");
- while($tok !== false) {
- $lines[] = $tok;
- $tok = strtok("\r\n");
- }
- return $lines;
- }
- // Form sent
- if (isset($_GET['lang'])):
- $lang = $_GET['lang'];
- if (strlen($lang) != 2) {
- errmsg('Invalid language', 'This language is invalid.');
- } else {
- $engMessages = getTranslationFile('messages.en');
- $langMessages = getTranslationFile('messages.'. $lang);
- if ($langMessages === false) {
- errmsg('Invalid language', 'This language is invalid.');
- } else {
- $yaml = new Yaml();
- $engGroups = $yaml->loadString($engMessages);
- $langGroups = $yaml->loadString($langMessages);
- $mustTranslate = [];
- foreach($engGroups as $groupName => $strings) {
- if (!isset($langGroups[$groupName]))
- $mustTranslate[$groupName] = $strings;
- else {
- foreach($strings as $k => $v) {
- if (!isset($langGroups[$groupName][$k]))
- $mustTranslate[$groupName][$k] = $v;
- }
- }
- }
- echo '<h1>The following messages still need to be translated:</h1>';
- echo '<table><tr><th>Path</th><th>English translation</th></tr>';
- foreach($mustTranslate as $group => $strings) {
- foreach($strings as $k => $v) {
- echo '<tr><td><code>'. $group .'.'. $k .'</code></td><td>'. strip_tags($v). '</td></tr>';
- }
- }
- if(count($mustTranslate) === 0) {
- echo '<tr><td colspan=2>Everything has been translated so far.</td></tr>';
- }
- echo '</table><a href="?" id="return">← Return</a>';
- }
- }
- else:
- ?>
- <h1>Raddit Language translation to-do tool</h1>
- <p>
- With this tool, you can see what text has not been translated in the specified language.
- </p>
- <form>
- <label for="lang">
- Language code
- </label>
- <input name="lang" id="lang" placeholder="de" /><br />
- <input type="submit" value="Check" />
- </form>
- <?php endif; ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement