Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Element
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
林焕东
Element
Commits
f4ac3faa
Commit
f4ac3faa
authored
Oct 28, 2016
by
杨奕
Committed by
GitHub
Oct 28, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #702 from QingWei-Li/feat/locale-options
Locale: add format
parents
2d09b959
472a7ef9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
1 deletion
+51
-1
src/locale/format.js
src/locale/format.js
+47
-0
src/locale/index.js
src/locale/index.js
+4
-1
No files found.
src/locale/format.js
0 → 100644
View file @
f4ac3faa
/**
* String format template
* - Inspired:
* https://github.com/Matt-Esch/string-template/index.js
*/
const
RE_NARGS
=
/
(
%|
)\{([
0-9a-zA-Z_
]
+
)\}
/g
;
export
default
function
(
Vue
)
{
const
{
hasOwn
}
=
Vue
.
util
;
/**
* template
*
* @param {String} string
* @param {Array} ...args
* @return {String}
*/
function
template
(
string
,
...
args
)
{
if
(
args
.
length
===
1
&&
typeof
args
[
0
]
===
'
object
'
)
{
args
=
args
[
0
];
}
if
(
!
args
||
!
args
.
hasOwnProperty
)
{
args
=
{};
}
return
string
.
replace
(
RE_NARGS
,
(
match
,
prefix
,
i
,
index
)
=>
{
let
result
;
if
(
string
[
index
-
1
]
===
'
{
'
&&
string
[
index
+
match
.
length
]
===
'
}
'
)
{
return
i
;
}
else
{
result
=
hasOwn
(
args
,
i
)
?
args
[
i
]
:
null
;
if
(
result
===
null
||
result
===
undefined
)
{
return
''
;
}
return
result
;
}
});
}
return
template
;
}
src/locale/index.js
View file @
f4ac3faa
import
defaultLang
from
'
element-ui/src/locale/lang/zh-cn
'
;
import
defaultLang
from
'
element-ui/src/locale/lang/zh-cn
'
;
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
;
import
Format
from
'
./format
'
;
const
format
=
Format
(
Vue
);
let
lang
=
defaultLang
;
let
lang
=
defaultLang
;
export
const
$t
=
function
(
path
,
options
)
{
export
const
$t
=
function
(
path
,
options
)
{
...
@@ -13,7 +16,7 @@ export const $t = function(path, options) {
...
@@ -13,7 +16,7 @@ export const $t = function(path, options) {
for
(
var
i
=
0
,
j
=
array
.
length
;
i
<
j
;
i
++
)
{
for
(
var
i
=
0
,
j
=
array
.
length
;
i
<
j
;
i
++
)
{
var
property
=
array
[
i
];
var
property
=
array
[
i
];
var
value
=
current
[
property
];
var
value
=
current
[
property
];
if
(
i
===
j
-
1
)
return
value
;
if
(
i
===
j
-
1
)
return
format
(
value
,
options
)
;
if
(
!
value
)
return
''
;
if
(
!
value
)
return
''
;
current
=
value
;
current
=
value
;
}
}
...
...
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