ソースを参照

Add option for setting locale

Local can be specified as `<table data-locale="fr-FR"></table>` or as option pased to $table.bootstrapTable({ locale: "fr-FR"})`

Checks for locale as specified in options, then if not found tries translating `_` to '-`, and if not found tries short two letter language code, and if all else fails, uses the default (last locale file) loaded.
Troy Morehouse 10 年 前
コミット
50a83fe8db
1 ファイル変更16 行追加5 行削除
  1. 16 5
      src/bootstrap-table.js

+ 16 - 5
src/bootstrap-table.js

@@ -452,11 +452,22 @@
         this.initServer();
     };
 
-    BootstrapTable.prototype.initLocaler = function () {
-        // apply locale if found, otherwaise use default/last loaded
-        if (this.options.locale && this.locales[this.options.locale]) {
-            $.extend(this.options, $.fn.bootstrapTable.locales[this.options.locale]);
-        }
+    BootstrapTable.prototype.initLocale = function () {
+		if (this.options.locale) {
+			var parts = this.options.locale.split(/-|_/);
+			parts[0].toLowerCase();
+			parts[1] && parts[1].toUpperCase();
+			if ($.fn.bootstrapTable.locales[this.options.locale]) {
+				// locale as requested
+				$.extend(this.options, $.fn.bootstrapTable.locales[this.options.locale]);
+			} else if ($.fn.bootstrapTable.locales[parts.join('-')]) {
+				// locale with sep set to - (in case original was specified with _)
+				$.extend(this.options, $.fn.bootstrapTable.locales[parts.join('-')]);
+			} else if ($.fn.bootstrapTable.locales[parts[0]]) {
+				// short locale language code (i.e. 'en')
+				$.extend(this.options, $.fn.bootstrapTable.locales[parts[0]]);
+			}
+		}
     };
     
     BootstrapTable.prototype.initContainer = function () {