简体   繁体   English

MySQL / PHP for HTML / javascript i18n有哪些替代方案?

[英]What are the alternatives to MySQL + PHP for HTML/javascript i18n?

I am looking at supporting multiple languages for an HTML5 application which does not rely on PHP nor MYSQL. 我正在为不依赖PHP或MYSQL的HTML5应用程序支持多种语言。 What are the best existing frameworks? 最好的现有框架是什么? Does anyone has experiences relying on sed? 有没有人有依赖sed的经验?

The easiest way to support multiple languages without php nor mysql is to simply make a new page for every language. 在没有php和mysql的情况下支持多种语言的最简单方法是为每种语言简单地创建一个新页面。 If you have all your javascript setup done in external files (like it should be done normally), then this method can be very useful 如果您所有的javascript设置都在外部文件中完成(就像应该正常进行一样),那么此方法会非常有用

You have to prepare the localized text in your JavaScript file(s), then you can do it client side ( ns.localize can be implemented better): 您必须在JavaScript文件中准备本地化的文本,然后才能在客户端进行操作( ns.localize可以更好地实现):

<!DOCTYPE html>
<html>
    <head>
        <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js'></script>
        <script src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js'></script>
        <script>
            window.ns = window.ns || { };

            /* Begin file i18n.js */
            ns.language = 'en';
            ns.i18n = { };
            ns.localize = function () {
                jQuery.each(ns.i18n[ns.language], function (key, value) {
                    $('.' + key).text(ns.i18n[ns.language][key]);
                });
            };
            /* End file i18n.js */

            /* Begin file i18n.en.js */
            ns.i18n['en'] = { };
            ns.i18n['en']['title'] = 'Welcome';
            ns.i18n['en']['body'] = 'It works!';
            ns.i18n['en']['choice'] = 'Choose your language:';
            /* End file i18n.en.js */

            /* Begin file i18n.it.js */
            ns.i18n['it'] = { };
            ns.i18n['it']['title'] = 'Benvenuto';
            ns.i18n['it']['body'] = 'Funziona!';
            ns.i18n['it']['choice'] = 'Scegli la tua lingua:';
            /* End file i18n.it.js */

            $(document).ready(function () {
                ns.localize();
                $('.language').change(function () {
                    var language =$(this).val(); 
                    ns.language = language;
                    ns.localize();
                });
            });
        </script>
        <link href='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css' rel='stylesheet' />
        <title class='title'>i18n</title>
    </head>
    <body>
        <h1 class='title'>i18n</h1>
        <p class='body'>Test.</p>
        <p>
            <span class='choice'>Something:</span>
            <select class='language'>
                <option value='en'>English</option>
                <option value='it'>Italian</option>
            </select>
        </p>
    </body>
</html>

You'd need some dynamic (web server) language to replace the language, or you'd need to render all code once and serve a different copy for each language. 您需要某种动态(Web服务器)语言来替换该语言,或者您需要一次渲染所有代码并为每种语言提供不同的副本。

Zend_Translate may be helpful, if you want to go PHP. 如果您想使用PHP,则Zend_Translate可能会有所帮助。

You don't need to use MySQL, you could use arrays, CVS files, and a whole range of other methods.( 您不需要使用MySQL,可以使用数组,CVS文件以及其他各种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM