| 1 | <!DOCTYPE html> |
|---|
| 2 | <!-- |
|---|
| 3 | Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved. |
|---|
| 4 | For licensing, see LICENSE.md or http://ckeditor.com/license |
|---|
| 5 | --> |
|---|
| 6 | <html> |
|---|
| 7 | <head> |
|---|
| 8 | <meta charset="utf-8"> |
|---|
| 9 | <title>User Interface Globalization — CKEditor Sample</title> |
|---|
| 10 | <script src="//cdn.ckeditor.com/4.6.2/full/ckeditor.js"></script> |
|---|
| 11 | <script src="assets/uilanguages/languages.js"></script> |
|---|
| 12 | <link rel="stylesheet" href="sample.css"> |
|---|
| 13 | </head> |
|---|
| 14 | <body> |
|---|
| 15 | <h1 class="samples"> |
|---|
| 16 | <a href="index.html">CKEditor Samples</a> » User Interface Languages |
|---|
| 17 | </h1> |
|---|
| 18 | <div class="warning deprecated"> |
|---|
| 19 | This sample is not maintained anymore. Check out its <a href="http://sdk.ckeditor.com/samples/uilanguages.html">brand new version in CKEditor SDK</a>. |
|---|
| 20 | </div> |
|---|
| 21 | <div class="description"> |
|---|
| 22 | <p> |
|---|
| 23 | This sample shows how to automatically replace <code><textarea></code> elements |
|---|
| 24 | with a CKEditor instance with an option to change the language of its user interface. |
|---|
| 25 | </p> |
|---|
| 26 | <p> |
|---|
| 27 | It pulls the language list from CKEditor <code>_languages.js</code> file that contains the list of supported languages and creates |
|---|
| 28 | a drop-down list that lets the user change the UI language. |
|---|
| 29 | </p> |
|---|
| 30 | <p> |
|---|
| 31 | By default, CKEditor automatically localizes the editor to the language of the user. |
|---|
| 32 | The UI language can be controlled with two configuration options: |
|---|
| 33 | <code><a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-language">language</a></code> and |
|---|
| 34 | <code><a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-defaultLanguage"> |
|---|
| 35 | defaultLanguage</a></code>. The <code>defaultLanguage</code> setting specifies the |
|---|
| 36 | default CKEditor language to be used when a localization suitable for user's settings is not available. |
|---|
| 37 | </p> |
|---|
| 38 | <p> |
|---|
| 39 | To specify the user interface language that will be used no matter what language is |
|---|
| 40 | specified in user's browser or operating system, set the <code>language</code> property: |
|---|
| 41 | </p> |
|---|
| 42 | <pre class="samples"> |
|---|
| 43 | CKEDITOR.replace( '<em>textarea_id</em>', { |
|---|
| 44 | // Load the German interface. |
|---|
| 45 | <strong>language: 'de'</strong> |
|---|
| 46 | });</pre> |
|---|
| 47 | <p> |
|---|
| 48 | Note that <code><em>textarea_id</em></code> in the code above is the <code>id</code> attribute of |
|---|
| 49 | the <code><textarea></code> element to be replaced. |
|---|
| 50 | </p> |
|---|
| 51 | </div> |
|---|
| 52 | <form action="sample_posteddata.php" method="post"> |
|---|
| 53 | <p> |
|---|
| 54 | Available languages (<span id="count"> </span> languages!):<br> |
|---|
| 55 | <script> |
|---|
| 56 | |
|---|
| 57 | document.write( '<select disabled="disabled" id="languages" onchange="createEditor( this.value );">' ); |
|---|
| 58 | |
|---|
| 59 | // Get the language list from the _languages.js file. |
|---|
| 60 | for ( var i = 0 ; i < window.CKEDITOR_LANGS.length ; i++ ) { |
|---|
| 61 | document.write( |
|---|
| 62 | '<option value="' + window.CKEDITOR_LANGS[i].code + '">' + |
|---|
| 63 | window.CKEDITOR_LANGS[i].name + |
|---|
| 64 | '</option>' ); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | document.write( '</select>' ); |
|---|
| 68 | |
|---|
| 69 | </script> |
|---|
| 70 | <br> |
|---|
| 71 | <span style="color: #888888"> |
|---|
| 72 | (You may see strange characters if your system does not support the selected language) |
|---|
| 73 | </span> |
|---|
| 74 | </p> |
|---|
| 75 | <p> |
|---|
| 76 | <div id="editor1" contenteditable="true" style="margin-top:110px;">test</div> |
|---|
| 77 | <script> |
|---|
| 78 | |
|---|
| 79 | CKEDITOR.disableAutoInline = true; |
|---|
| 80 | // Set the number of languages. |
|---|
| 81 | document.getElementById( 'count' ).innerHTML = window.CKEDITOR_LANGS.length; |
|---|
| 82 | |
|---|
| 83 | var editor; |
|---|
| 84 | |
|---|
| 85 | function createEditor( languageCode ) { |
|---|
| 86 | if ( editor ) |
|---|
| 87 | editor.destroy(); |
|---|
| 88 | |
|---|
| 89 | console.log(languageCode); |
|---|
| 90 | |
|---|
| 91 | // Replace the <textarea id="editor"> with an CKEditor |
|---|
| 92 | // instance, using default configurations. |
|---|
| 93 | editor = CKEDITOR.inline( 'editor1', { |
|---|
| 94 | language: languageCode, |
|---|
| 95 | |
|---|
| 96 | on: { |
|---|
| 97 | instanceReady: function() { |
|---|
| 98 | // Wait for the editor to be ready to set |
|---|
| 99 | // the language combo. |
|---|
| 100 | var languages = document.getElementById( 'languages' ); |
|---|
| 101 | languages.value = this.langCode; |
|---|
| 102 | languages.disabled = false; |
|---|
| 103 | |
|---|
| 104 | /*var container = document.getElementById( 'editor1' ); |
|---|
| 105 | if( languageCode == 'ug' || languageCode == 'fa' || languageCode == 'ar' || languageCode == 'he' ) |
|---|
| 106 | container.setAttribute( 'dir', 'rtl'); |
|---|
| 107 | else |
|---|
| 108 | container.setAttribute( 'dir', 'ltr');*/ |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | }); |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | // At page startup, load the default language: |
|---|
| 115 | createEditor( '' ); |
|---|
| 116 | |
|---|
| 117 | </script> |
|---|
| 118 | </p> |
|---|
| 119 | </form> |
|---|
| 120 | <div id="footer"> |
|---|
| 121 | <hr> |
|---|
| 122 | <p> |
|---|
| 123 | CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> |
|---|
| 124 | </p> |
|---|
| 125 | <p id="copy"> |
|---|
| 126 | Copyright © 2003-2017, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico |
|---|
| 127 | Knabben. All rights reserved. |
|---|
| 128 | </p> |
|---|
| 129 | </div> |
|---|
| 130 | </body> |
|---|
| 131 | </html> |
|---|