From 8ce2a244e9e4f7417f31571ac945c009429e36a7 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 11 Dec 2023 13:38:05 +0100 Subject: [PATCH] https://github.com/the-djmaze/snappymail/issues/1353#issuecomment-1849049228 --- public_html/translate.php | 179 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 public_html/translate.php diff --git a/public_html/translate.php b/public_html/translate.php new file mode 100644 index 000000000..6a7029f5c --- /dev/null +++ b/public_html/translate.php @@ -0,0 +1,179 @@ + $values) { + if (is_array($values)) { + foreach ($values as $key => $value) { + $data[$section][$key] = preg_replace('/\\R/', "\n", trim($value)); + } + } else if ('LANG_DIR' === $section) { + $data[$section] = $values; + } + } + return str_replace(' ', "\t", json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); +} + +if ('POST' === $_SERVER['REQUEST_METHOD']) { + try { + $file = tempnam(sys_get_temp_dir(), ''); + $zip = new ZipArchive(); + if (!$zip->open($file, ZIPARCHIVE::CREATE)) { + exit("Failed to create zip"); + } + $lang = $lang ?: 'new'; + $zip->addFromString("{$lang}/admin.json", toJSON($_POST['admin'])); + $zip->addFromString("{$lang}/user.json", toJSON($_POST['user'])); + $zip->close(); + header('Content-Type: application/zip'); + header('Content-disposition: attachment; filename="snappymail-'.$lang.'.zip"'); + header('Content-Length: ' . filesize($file)); + readfile($file); + } catch (\Throwable $e) { + echo $e->getMessage(); + } + unlink($file); + exit; +} + +// /home/rainloop/public_html/snappymail/v/0.0.0/static/js +$_ENV['SNAPPYMAIL_INCLUDE_AS_API'] = true; +require 'demo/index.php'; + +$root = APP_VERSION_ROOT_PATH . 'app/localization'; + +$en = [ + 'admin' => '', +// 'static' => '', + 'user' => '' +]; +foreach ($en as $name => $data) { + $en[$name] = json_decode(file_get_contents("{$root}/en/{$name}.json"), true); +} + +$languages = ['']; +foreach (glob("{$root}/*", GLOB_ONLYDIR) as $dir) { + $name = basename($dir); + if ('en' !== $name) { + $languages[] = ""; + } +} + +//print_r($languages); + +echo ' + + + + Translate + + +

Translate:

+
+ Show untranslated only + + + + + + +'; +foreach ($en as $name => $sections) { + echo ''; + $data = is_readable("{$root}/{$lang}/{$name}.json") ? json_decode(file_get_contents("{$root}/{$lang}/{$name}.json"), true) : []; + foreach ($sections as $section => $values) { + if (is_array($values)) { + echo ''; + foreach ($values as $key => $value) { + echo ''; +// echo ''; + echo ''; + echo ''; + echo ''; + } + } else if ('LANG_DIR' === $section) { + echo ''; + echo ''; + echo ''; + echo ''; + } + } + echo ''; +} +echo '
en'.$lang.'
'.$name.'
'.$section.'
'.$section.'/'.$key.''.htmlspecialchars($value).'
Text direction
'; +echo '
'; + +/* +