Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
persona
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hexang 息壤平台
persona
Commits
9340251a
Commit
9340251a
authored
12 years ago
by
Lloyd Hilaiel
Browse files
Options
Downloads
Patches
Plain Diff
make the format() function for l10n more ergonomic - don't require a third argument
parent
6a81e328
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/i18n.js
+7
-5
7 additions, 5 deletions
lib/i18n.js
resources/static/common/js/gettext.js
+7
-6
7 additions, 6 deletions
resources/static/common/js/gettext.js
with
14 additions
and
11 deletions
lib/i18n.js
+
7
−
5
View file @
9340251a
...
...
@@ -251,15 +251,17 @@ exports.languageFrom = function (locale) {
* of values for positional replacement.
*
* Named Example:
* format("%(salutation)s %(place)s", {salutation: "Hello", place: "World"}
, true
);
* format("%(salutation)s %(place)s", {salutation: "Hello", place: "World"});
* Positional Example:
* format("%s %s", ["Hello", "World"]);
*/
var
format
=
exports
.
format
=
function
(
fmt
,
obj
,
named
)
{
if
(
!
fmt
)
return
""
;
if
(
named
)
{
return
fmt
.
replace
(
/%
\(\w
+
\)
s/g
,
function
(
match
){
return
String
(
obj
[
match
.
slice
(
2
,
-
2
)])});
}
else
{
if
(
!
fmt
)
return
""
;
if
(
Array
.
isArray
(
obj
)
||
named
===
false
)
{
return
fmt
.
replace
(
/%s/g
,
function
(
match
){
return
String
(
obj
.
shift
())});
}
else
if
(
typeof
obj
===
'
object
'
||
named
===
true
)
{
return
fmt
.
replace
(
/%
\(\s
*
([^
)
]
+
)\s
*
\)
/g
,
function
(
m
,
v
){
return
String
(
obj
[
v
]);
});
}
};
This diff is collapsed.
Click to expand it.
resources/static/common/js/gettext.js
+
7
−
6
View file @
9340251a
...
...
@@ -20,14 +20,16 @@
},
// See lib/i18n.js format docs
format
:
function
(
fmt
,
obj
,
named
)
{
if
(
!
fmt
)
return
""
;
if
(
!
fmt
.
replace
)
{
if
(
!
fmt
)
return
""
;
if
(
!
fmt
.
replace
)
{
return
fmt
;
}
if
(
named
)
{
return
fmt
.
replace
(
/%
\(\w
+
\)
s/g
,
function
(
match
){
return
String
(
obj
[
match
.
slice
(
2
,
-
2
)])});
}
else
{
if
(
_
.
isArray
(
obj
)
||
named
===
false
)
{
return
fmt
.
replace
(
/%s/g
,
function
(
match
){
return
String
(
obj
.
shift
())});
}
else
if
(
_
.
isObject
(
obj
)
||
named
===
true
)
{
return
fmt
.
replace
(
/%
\(\s
*
([^
)
]
+
)\s
*
\)
/g
,
function
(
m
,
v
){
return
String
(
obj
[
v
]);
});
}
}
};
...
...
@@ -40,5 +42,4 @@
var
gt
=
new
Gettext
(
params
);
window
.
gettext
=
gt
.
gettext
.
bind
(
gt
);
window
.
format
=
gt
.
format
.
bind
(
gt
);
}());
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment