/Disciples/Disciples/ckeditor/_source/core/lang.js

https://bitbucket.org/davcar/bvcms/ · JavaScript · 147 lines · 101 code · 10 blank · 36 comment · 7 complexity · c2cdf4a3508a7ada1135df64cbf2aadf MD5 · raw file

  1. /*
  2. Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
  3. For licensing, see LICENSE.html or http://ckeditor.com/license
  4. */
  5. (function()
  6. {
  7. var loadedLangs = {};
  8. CKEDITOR.lang =
  9. {
  10. /**
  11. * The list of languages available in the editor core.
  12. * @type Object
  13. * @example
  14. * alert( CKEDITOR.lang.en ); // "true"
  15. */
  16. languages :
  17. {
  18. 'af' : 1,
  19. 'ar' : 1,
  20. 'bg' : 1,
  21. 'bn' : 1,
  22. 'bs' : 1,
  23. 'ca' : 1,
  24. 'cs' : 1,
  25. 'da' : 1,
  26. 'de' : 1,
  27. 'el' : 1,
  28. 'en-au' : 1,
  29. 'en-ca' : 1,
  30. 'en-uk' : 1,
  31. 'en' : 1,
  32. 'eo' : 1,
  33. 'es' : 1,
  34. 'et' : 1,
  35. 'eu' : 1,
  36. 'fa' : 1,
  37. 'fi' : 1,
  38. 'fo' : 1,
  39. 'fr-ca' : 1,
  40. 'fr' : 1,
  41. 'gl' : 1,
  42. 'gu' : 1,
  43. 'he' : 1,
  44. 'hi' : 1,
  45. 'hr' : 1,
  46. 'hu' : 1,
  47. 'is' : 1,
  48. 'it' : 1,
  49. 'ja' : 1,
  50. 'km' : 1,
  51. 'ko' : 1,
  52. 'lt' : 1,
  53. 'lv' : 1,
  54. 'mn' : 1,
  55. 'ms' : 1,
  56. 'nb' : 1,
  57. 'nl' : 1,
  58. 'no' : 1,
  59. 'pl' : 1,
  60. 'pt-br' : 1,
  61. 'pt' : 1,
  62. 'ro' : 1,
  63. 'ru' : 1,
  64. 'sk' : 1,
  65. 'sl' : 1,
  66. 'sr-latn' : 1,
  67. 'sr' : 1,
  68. 'sv' : 1,
  69. 'th' : 1,
  70. 'tr' : 1,
  71. 'uk' : 1,
  72. 'vi' : 1,
  73. 'zh-cn' : 1,
  74. 'zh' : 1
  75. },
  76. /**
  77. * Loads a specific language file, or auto detect it. A callback is
  78. * then called when the file gets loaded.
  79. * @param {String} languageCode The code of the language file to be
  80. * loaded. If "autoDetect" is set to true, this language will be
  81. * used as the default one, if the detect language is not
  82. * available in the core.
  83. * @param {Boolean} autoDetect Indicates that the function must try to
  84. * detect the user language and load it instead.
  85. * @param {Function} callback The function to be called once the
  86. * language file is loaded. Two parameters are passed to this
  87. * function: the language code and the loaded language entries.
  88. * @example
  89. */
  90. load : function( languageCode, defaultLanguage, callback )
  91. {
  92. if ( !languageCode )
  93. languageCode = this.detect( defaultLanguage );
  94. if ( !this[ languageCode ] )
  95. {
  96. CKEDITOR.scriptLoader.load( CKEDITOR.getUrl(
  97. 'lang/' + languageCode + '.js' ),
  98. function()
  99. {
  100. callback( languageCode, this[ languageCode ] );
  101. }
  102. , this );
  103. }
  104. else
  105. callback( languageCode, this[ languageCode ] );
  106. },
  107. /**
  108. * Returns the language that best fit the user language. For example,
  109. * suppose that the user language is "pt-br". If this language is
  110. * supported by the editor, it is returned. Otherwise, if only "pt" is
  111. * supported, it is returned instead. If none of the previous are
  112. * supported, a default language is then returned.
  113. * @param {String} defaultLanguage The default language to be returned
  114. * if the user language is not supported.
  115. * @returns {String} The detected language code.
  116. * @example
  117. * alert( CKEDITOR.lang.detect( 'en' ) ); // e.g., in a German browser: "de"
  118. */
  119. detect : function( defaultLanguage )
  120. {
  121. var languages = this.languages;
  122. var parts = ( navigator.userLanguage || navigator.language )
  123. .toLowerCase()
  124. .match( /([a-z]+)(?:-([a-z]+))?/ ),
  125. lang = parts[1],
  126. locale = parts[2];
  127. if ( languages[ lang + '-' + locale ] )
  128. lang = lang + '-' + locale;
  129. else if ( !languages[ lang ] )
  130. lang = null;
  131. CKEDITOR.lang.detect = lang ?
  132. function() { return lang; } :
  133. function( defaultLanguage ) { return defaultLanguage; };
  134. return lang || defaultLanguage;
  135. }
  136. };
  137. })();