Skip to content

Commit 4ddcc8a

Browse files
author
Sergey Dolin
committed
v 1.0.7 improve setCurrentLocale
1 parent 5aea20f commit 4ddcc8a

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

index.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,23 @@ function currentLocale(){
1414
}
1515

1616
function setCurrentLocale(sLocale){
17-
locale=sLocale;
17+
if (locales[sLocale])
18+
locale=sLocale;
19+
else{
20+
let i=sLocale.indexOf('-');
21+
if (i>0){
22+
return setCurrentLocale(sLocale.substring(0,i));
23+
}else{
24+
i=sLocale.indexOf('_');
25+
if (i>0){
26+
return setCurrentLocale(sLocale.substring(0,i));
27+
}else{
28+
if (locales.length>0){
29+
setCurrentLocale(locales[0]);
30+
}
31+
}
32+
}
33+
}
1834
}
1935

2036
function isLocalized(){

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
],
66
"name": "mongoose-localize",
77
"description": "A module to convert mongoose model property to set of localized properties.",
8-
"version": "1.0.6",
8+
"version": "1.0.7",
99
"keywords": [
1010
"mongoose",
1111
"localize",

0 commit comments

Comments
 (0)