Skip to content

Commit e902dad

Browse files
author
Sergey Melyukov
committed
extract/l10n: extract tokens from tmpl enum states
1 parent b3258de commit e902dad

File tree

1 file changed

+51
-22
lines changed

1 file changed

+51
-22
lines changed

lib/extract/l10n/index.js

+51-22
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,57 @@ var tmplAt = require('basisjs-tools-ast').tmpl;
2424
var bindName = token[1];
2525
if (l10nPrefix.test(bindName))
2626
{
27-
var l10nTokenRef = bindName.substr(5);
28-
var l10nToken = flow.l10n.getToken(l10nTokenRef);
29-
var name = l10nToken.name;
30-
var dictionary = l10nToken.dictionary;
31-
32-
fconsole.log(name + ' @ ' + dictionary.file.relpath);
33-
34-
var tmplRef = {
35-
file: this.file,
36-
name: name,
37-
dictionary: dictionary,
38-
key: l10nTokenRef,
39-
host: token,
40-
idx: 1
41-
};
42-
43-
dictionary.file.jsRefCount++;
44-
dictionary.addRef(this.file);
45-
this.file.link(dictionary.file);
46-
l10nToken.addRef(this.file, tmplRef);
47-
48-
tmplRefs.push(tmplRef);
27+
var parts = bindName.substr(5).split('@');
28+
var tokenName = parts[0];
29+
var dictFilename = parts[1];
30+
var tokenNameParts = tokenName.match(/^(.+?)\.{(.+?)}/);
31+
var stateName;
32+
var tokenQueue = [];
33+
34+
if (tokenNameParts && tokenNameParts.length == 3) {
35+
tokenName = tokenNameParts[1];
36+
stateName = tokenNameParts[2];
37+
}
38+
39+
tokenQueue.push(tokenName + '@' + dictFilename);
40+
41+
if (stateName && this.file.decl.states.hasOwnProperty(stateName)){
42+
var stateVariants = this.file.decl.states[stateName].enum;
43+
44+
if (stateVariants)
45+
{
46+
stateVariants.forEach(function(variant){
47+
tokenQueue.push(tokenName + '.' + variant + '@' + dictFilename);
48+
});
49+
}
50+
}
51+
52+
for (var i = 0; i < tokenQueue.length; i++)
53+
{
54+
var l10nTokenRef = tokenQueue[i];
55+
56+
var l10nToken = flow.l10n.getToken(l10nTokenRef);
57+
var name = l10nToken.name;
58+
var dictionary = l10nToken.dictionary;
59+
60+
fconsole.log(name + ' @ ' + dictionary.file.relpath);
61+
62+
var tmplRef = {
63+
file: this.file,
64+
name: name,
65+
dictionary: dictionary,
66+
key: l10nTokenRef,
67+
host: token,
68+
idx: 1
69+
};
70+
71+
dictionary.file.jsRefCount++;
72+
dictionary.addRef(this.file);
73+
this.file.link(dictionary.file);
74+
l10nToken.addRef(this.file, tmplRef);
75+
76+
tmplRefs.push(tmplRef);
77+
}
4978
}
5079
},
5180
attr: function(token){

0 commit comments

Comments
 (0)