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
0c393cf2
Commit
0c393cf2
authored
8 years ago
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move some utility methods to utils.js
parent
01e10a9b
master
1.0.x
2.0.x
3.0
3.1.x
appsettings
bookmarks-pep-node-settings
bottom-typing-notifications
converse-omemo-subview
es2015-minifier
full-height-controlbox
groupchat-notifications
indexeddb
karma
match-media
multi-session-nicks
nexedi
selenium
split-muc-views
webpack-karma
xep-0198
3.3.2
3.2.0-rc
v7.0.4
v7.0.3
v7.0.2
v7.0.1
v7.0.0
v6.0.1
v6.0.0
v5.0.5
v5.0.4
v5.0.3
v5.0.2
v5.0.1
v5.0.0
v4.2.0
v4.1.2
v4.1.1
v4.1.0
v4.0.6
v4.0.5
v4.0.4
v4.0.3
v4.0.2
v4.0.1
v4.0.0
v3.3.4
v3.3.3
v3.3.1
v3.3.0
v3.2.1
v3.2.0
v3.1.1
v3.1.0
v3.0.2
v3.0.1
v3.0.0
v2.0.6
v2.0.5
v2.0.4
v2.0.3
v2.0.2
v2.0.1
v2.0.0
v1.0.7
v1.0.6
v1.0.5
v1.0.4
nexedi-v7.0.0dev1
nexedi-v7.0.0dev
nexedi-v4.2.0
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
46 deletions
+46
-46
src/converse-core.js
src/converse-core.js
+2
-46
src/utils.js
src/utils.js
+44
-0
No files found.
src/converse-core.js
View file @
0c393cf2
...
...
@@ -197,55 +197,11 @@
};
};
this
.
isLocaleAvailable
=
function
(
locale
,
available
)
{
/* Check whether the locale or sub locale (e.g. en-US, en) is supported.
*
* Parameters:
* (Function) available - returns a boolean indicating whether the locale is supported
*/
if
(
available
(
locale
))
{
return
locale
;
}
else
{
var
sublocale
=
locale
.
split
(
"
-
"
)[
0
];
if
(
sublocale
!==
locale
&&
available
(
sublocale
))
{
return
sublocale
;
}
}
};
this
.
detectLocale
=
function
(
library_check
)
{
/* Determine which locale is supported by the user's system as well
* as by the relevant library (e.g. converse.js or moment.js).
*
* Parameters:
* (Function) library_check - returns a boolean indicating whether the locale is supported
*/
var
locale
,
i
;
if
(
window
.
navigator
.
userLanguage
)
{
locale
=
this
.
isLocaleAvailable
(
window
.
navigator
.
userLanguage
,
library_check
);
}
if
(
window
.
navigator
.
languages
&&
!
locale
)
{
for
(
i
=
0
;
i
<
window
.
navigator
.
languages
.
length
&&
!
locale
;
i
++
)
{
locale
=
this
.
isLocaleAvailable
(
window
.
navigator
.
languages
[
i
],
library_check
);
}
}
if
(
window
.
navigator
.
browserLanguage
&&
!
locale
)
{
locale
=
this
.
isLocaleAvailable
(
window
.
navigator
.
browserLanguage
,
library_check
);
}
if
(
window
.
navigator
.
language
&&
!
locale
)
{
locale
=
this
.
isLocaleAvailable
(
window
.
navigator
.
language
,
library_check
);
}
if
(
window
.
navigator
.
systemLanguage
&&
!
locale
)
{
locale
=
this
.
isLocaleAvailable
(
window
.
navigator
.
systemLanguage
,
library_check
);
}
return
locale
||
'
en
'
;
};
if
(
!
moment
.
locale
)
{
//moment.lang is deprecated after 2.8.1, use moment.locale instead
moment
.
locale
=
moment
.
lang
;
}
moment
.
locale
(
thi
s
.
detectLocale
(
this
.
isMomentLocale
));
this
.
i18n
=
settings
.
i18n
?
settings
.
i18n
:
locales
[
thi
s
.
detectLocale
(
this
.
isConverseLocale
)]
||
{};
moment
.
locale
(
util
s
.
detectLocale
(
this
.
isMomentLocale
));
this
.
i18n
=
settings
.
i18n
?
settings
.
i18n
:
locales
[
util
s
.
detectLocale
(
this
.
isConverseLocale
)]
||
{};
// Translation machinery
// ---------------------
...
...
This diff is collapsed.
Click to expand it.
src/utils.js
View file @
0c393cf2
...
...
@@ -149,6 +149,50 @@
return
str
;
},
isLocaleAvailable
:
function
(
locale
,
available
)
{
/* Check whether the locale or sub locale (e.g. en-US, en) is supported.
*
* Parameters:
* (Function) available - returns a boolean indicating whether the locale is supported
*/
if
(
available
(
locale
))
{
return
locale
;
}
else
{
var
sublocale
=
locale
.
split
(
"
-
"
)[
0
];
if
(
sublocale
!==
locale
&&
available
(
sublocale
))
{
return
sublocale
;
}
}
},
detectLocale
:
function
(
library_check
)
{
/* Determine which locale is supported by the user's system as well
* as by the relevant library (e.g. converse.js or moment.js).
*
* Parameters:
* (Function) library_check - returns a boolean indicating whether the locale is supported
*/
var
locale
,
i
;
if
(
window
.
navigator
.
userLanguage
)
{
locale
=
utils
.
isLocaleAvailable
(
window
.
navigator
.
userLanguage
,
library_check
);
}
if
(
window
.
navigator
.
languages
&&
!
locale
)
{
for
(
i
=
0
;
i
<
window
.
navigator
.
languages
.
length
&&
!
locale
;
i
++
)
{
locale
=
utils
.
isLocaleAvailable
(
window
.
navigator
.
languages
[
i
],
library_check
);
}
}
if
(
window
.
navigator
.
browserLanguage
&&
!
locale
)
{
locale
=
utils
.
isLocaleAvailable
(
window
.
navigator
.
browserLanguage
,
library_check
);
}
if
(
window
.
navigator
.
language
&&
!
locale
)
{
locale
=
utils
.
isLocaleAvailable
(
window
.
navigator
.
language
,
library_check
);
}
if
(
window
.
navigator
.
systemLanguage
&&
!
locale
)
{
locale
=
utils
.
isLocaleAvailable
(
window
.
navigator
.
systemLanguage
,
library_check
);
}
return
locale
||
'
en
'
;
},
isOTRMessage
:
function
(
message
)
{
var
$body
=
$
(
message
).
children
(
'
body
'
),
text
=
(
$body
.
length
>
0
?
$body
.
text
()
:
undefined
);
...
...
This diff is collapsed.
Click to expand it.
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