Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
f75b3a07
Commit
f75b3a07
authored
May 27, 2015
by
thierrytiti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
I18N: detect language for MomentJS
user language detection in order to format date and time in correct locale
parent
7c21341d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
18 deletions
+36
-18
converse.js
converse.js
+33
-16
docs/CHANGES.rst
docs/CHANGES.rst
+1
-0
main.js
main.js
+1
-1
non_amd.html
non_amd.html
+1
-1
No files found.
converse.js
View file @
f75b3a07
...
...
@@ -215,35 +215,52 @@
// Translation machinery
// ---------------------
this
.
isAvailableLocale
=
function
(
locale
)
{
//test for MomentJS
this
.
testMomentLocale
=
function
(
locale
){
oldlang
=
moment
.
locale
();
newlang
=
moment
.
locale
(
locale
);
return
(
newlang
!=
oldlang
);
}
//test for COnverseJS
this
.
testConverseLocale
=
function
(
locale
){
return
(
locales
[
locale
]);
}
//Check locale and sub locale (e.g. locale: en-US sublocale: en)
this
.
isAvailableLocale
=
function
(
locale
,
available
)
{
ret
=
null
;
if
(
locales
[
locale
]
)
{
ret
=
locale
s
[
locale
]
;
if
(
available
(
locale
)
)
{
ret
=
locale
;
}
else
{
sublocale
=
locale
.
split
(
"
-
"
)[
0
];
if
(
sublocale
!=
locale
&&
locales
[
sublocale
]
)
{
ret
=
locales
[
sublocale
]
;
if
(
sublocale
!=
locale
&&
available
(
sublocale
)
)
{
ret
=
sublocale
;
}
}
return
ret
;
};
this
.
detectLocale
=
function
()
{
//Check Browser information
this
.
detectLocale
=
function
(
testLocale
)
{
ret
=
null
;
if
(
window
.
navigator
.
userLanguage
)
{
ret
=
this
.
isAvailableLocale
(
window
.
navigator
.
userLanguage
);
}
else
if
(
window
.
navigator
.
languages
&&
!
ret
)
{
if
(
window
.
navigator
.
userLanguage
)
ret
=
this
.
isAvailableLocale
(
window
.
navigator
.
userLanguage
,
testLocale
);
else
if
(
window
.
navigator
.
languages
&&
!
ret
)
{
for
(
var
i
=
0
;
i
<
window
.
navigator
.
languages
.
length
&&
!
ret
;
i
++
)
{
ret
=
this
.
isAvailableLocale
(
window
.
navigator
.
languages
[
i
]);
ret
=
this
.
isAvailableLocale
(
window
.
navigator
.
languages
[
i
]
,
testLocale
);
}
}
else
if
(
window
.
navigator
.
browserLanguage
&&
!
ret
)
ret
=
this
.
isAvailableLocale
(
window
.
navigator
.
browserLanguage
);
else
if
(
window
.
navigator
.
language
&&
!
ret
)
ret
=
this
.
isAvailableLocale
(
window
.
navigator
.
language
);
else
if
(
window
.
navigator
.
systemLanguage
&&
!
ret
)
ret
=
this
.
isAvailableLocale
(
window
.
navigator
.
systemLanguage
);
else
{
ret
=
locales
.
en
;
}
else
if
(
window
.
navigator
.
browserLanguage
&&
!
ret
)
ret
=
this
.
isAvailableLocale
(
window
.
navigator
.
browserLanguage
,
testLocale
);
else
if
(
window
.
navigator
.
language
&&
!
ret
)
ret
=
this
.
isAvailableLocale
(
window
.
navigator
.
language
,
testLocale
);
else
if
(
window
.
navigator
.
systemLanguage
&&
!
ret
)
ret
=
this
.
isAvailableLocale
(
window
.
navigator
.
systemLanguage
,
testLocale
);
if
(
!
ret
)
{
ret
=
'
en
'
;
}
return
ret
;
};
this
.
i18n
=
settings
.
i18n
?
settings
.
i18n
:
this
.
detectLocale
();
this
.
i18n
=
settings
.
i18n
?
settings
.
i18n
:
locales
[
this
.
detectLocale
(
this
.
testConverseLocale
)];
if
(
!
moment
.
locale
)
moment
.
locale
=
moment
.
lang
;
//moment.lang is deprecated after 2.8.1, use moment.locale instead
moment
.
locale
(
this
.
detectLocale
(
this
.
testMomentLocale
));
var
__
=
$
.
proxy
(
utils
.
__
,
this
);
var
___
=
utils
.
___
;
...
...
docs/CHANGES.rst
View file @
f75b3a07
...
...
@@ -16,6 +16,7 @@ Changelog
* I18N: Autodetection of User Locale if no i18n setting is set. [thierrytiti]
* CSS: Fonts Path: editabable $font-path via sass/variables.scss [thierrytiti]
* Add offline pretty status to enable translation [thierrytiti]
* I18N: Autodetection of User Locale for MomentJS Date and Time [thierrytiti]
0.9.3 (2015-05-01)
------------------
...
...
main.js
View file @
f75b3a07
...
...
@@ -26,7 +26,7 @@ require.config({
"
jquery-private
"
:
"
src/jquery-private
"
,
"
jquery.browser
"
:
"
components/jquery.browser/dist/jquery.browser
"
,
"
jquery.easing
"
:
"
components/jquery-easing-original/index
"
,
// XXX: Only required for https://conversejs.org website
"
moment
"
:
"
components/momentjs/m
oment
"
,
"
moment
"
:
"
components/momentjs/m
in/moment-with-langs
"
,
"
strophe-base64
"
:
"
components/strophejs/src/base64
"
,
"
strophe-bosh
"
:
"
components/strophejs/src/bosh
"
,
"
strophe-core
"
:
"
components/strophejs/src/core
"
,
...
...
non_amd.html
View file @
f75b3a07
...
...
@@ -39,7 +39,7 @@
<script
type=
"text/javascript"
src=
"components/backbone//backbone.js"
></script>
<script
type=
"text/javascript"
src=
"components/backbone.browserStorage/backbone.browserStorage.js"
></script>
<script
type=
"text/javascript"
src=
"components/backbone.overview/backbone.overview.js"
></script>
<script
type=
"text/javascript"
src=
"components/momentjs/m
oment
.js"
></script>
<script
type=
"text/javascript"
src=
"components/momentjs/m
in/moment-with-langs
.js"
></script>
<script
type=
"text/javascript"
src=
"components/jquery.browser/dist/jquery.browser.js"
></script>
<script
type=
"text/javascript"
src=
"components/typeahead.js/index.js"
></script>
<script
type=
"text/javascript"
src=
"components/jed/jed.js"
></script>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment