multi-languages.html 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>多语言支持 - Editor.md examples</title>
  6. <link rel="stylesheet" href="css/style.css" />
  7. <link rel="stylesheet" href="../css/editormd.css" />
  8. <link rel="shortcut icon" href="https://pandao.github.io/editor.md/favicon.ico" type="image/x-icon" />
  9. </head>
  10. <body>
  11. <div id="layout">
  12. <header>
  13. <h1>多语言支持(l18n)</h1>
  14. <p>multi-languages for l18n.
  15. <select id="lang-select">
  16. <option selected="selected">Languages</option>
  17. <option value="en">English (en)</option>
  18. <option value="zh-tw">繁體中文 (zh-tw)</option>
  19. <option value="zh-cn">简体中文 (zh-cn)</option>
  20. </select>
  21. </p>
  22. </header>
  23. <div id="test-editormd">
  24. <textarea style="display:none;">###多语言支持(l18n)
  25. 目前支持三种语言:简体中文、繁體中文、English,默认为简体中文 (zh-cn default)。
  26. ```html
  27. &lt;!-- English --&gt;
  28. &lt;script src="../dist/js/languages/en.js"&gt;&lt;/script&gt;
  29. &lt;!-- 繁體中文 --&gt;
  30. &lt;script src="../dist/js/languages/zh-tw.js"&gt;&lt;/script&gt;
  31. ```
  32. </textarea>
  33. </div>
  34. </div>
  35. <script src="js/jquery.min.js"></script>
  36. <script src="../editormd.js"></script>
  37. <!--<script src="../languages/en.js"></script>
  38. <script src="../languages/zh-tw.js"></script> -->
  39. <script type="text/javascript">
  40. var testEditor;
  41. $(function() {
  42. testEditor = editormd("test-editormd", {
  43. width: "90%",
  44. height: 640,
  45. emoji : true,
  46. path : '../lib/'
  47. });
  48. //console.log(editormd.defaults.lang);
  49. var lang = "zh-cn";
  50. // 动态加载语言包
  51. // Dynamic load language package
  52. $("#lang-select").change(function() {
  53. var value = $(this).val();
  54. var path = "../languages/";
  55. if (value == "zh-cn")
  56. {
  57. location.reload();
  58. }
  59. else
  60. {
  61. editormd.loadScript(path + value, function() {
  62. testEditor.lang = editormd.defaults.lang;
  63. // 只重建涉及语言包的部分,如工具栏、弹出对话框等
  64. testEditor.recreate();
  65. // 整个编辑器重建,预览HTML会重新生成,出现闪动
  66. //testEditor = editormd("test-editormd", {
  67. //width: "90%",
  68. //height: 640,
  69. //path : '../lib/'
  70. //});
  71. lang = value;
  72. console.log(lang, value, editormd.defaults.lang);
  73. });
  74. }
  75. });
  76. });
  77. </script>
  78. </body>
  79. </html>