Skip to content

Commit bddc02a

Browse files
committed
Add support for i18n tags
Resolves #5 This commit adds rules to consume `<i18n>` tags and highlight body text as JSON or YAML.
1 parent dfdc1ba commit bddc02a

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

Vue Component.sublime-syntax

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ contexts:
6565
- meta_prepend: true
6666
- include: script-tag
6767
- include: style-tag
68+
- include: i18n-tag
6869
- include: template-tag
6970

7071
###[ SCRIPT TAG ]#############################################################
@@ -535,6 +536,48 @@ contexts:
535536
3: source.sss.embedded.html
536537
4: comment.block.html punctuation.definition.comment.end.html
537538

539+
###[ I18N TAG ]###############################################################
540+
541+
i18n-tag:
542+
# https://github.com/kazupon/vue-i18n
543+
- match: (<)((?i:i18n)){{tag_name_break}}
544+
captures:
545+
1: punctuation.definition.tag.begin.html
546+
2: entity.name.tag.i18n.html
547+
push: i18n-open-tag-content
548+
- match: (</)((?i:i18n)){{tag_name_break}}
549+
captures:
550+
1: punctuation.definition.tag.begin.html
551+
2: entity.name.tag.i18n.html
552+
3: punctuation.definition.tag.end.html
553+
push: i18n-close-tag-content
554+
555+
i18n-close-tag-content:
556+
- meta_scope: meta.tag.i18n.end.html
557+
- include: tag-end
558+
559+
i18n-open-tag-content:
560+
- meta_scope: meta.tag.i18n.begin.html
561+
- match: '>'
562+
scope: punctuation.definition.tag.end.html
563+
set: i18n-content
564+
- include: tag-attributes
565+
- include: tag-end-self-closing
566+
567+
i18n-content:
568+
# expect json object or list
569+
- match: (?=(?:^|\s*)[{\[])
570+
embed: scope:source.json
571+
embed_scope: source.json.embedded.html
572+
escape: (?=(?:^\s*)?</(?i:i18n){{tag_name_break}})
573+
pop: 1
574+
# use yaml syntax otherwise (it also highlights json well!)
575+
- match: (?=(?:^|\s*)\S)
576+
embed: scope:source.yaml
577+
embed_scope: source.yaml.embedded.html
578+
escape: (?=(?:^\s*)?</(?i:i18n){{tag_name_break}})
579+
pop: 1
580+
538581
###[ TEMPLATE TAG ]###########################################################
539582

540583
template-tag:

tests/syntax_test_i18n.vue

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// SYNTAX TEST "Vue Component.sublime-syntax"
2+
3+
<!--
4+
Test i18n loader tags
5+
6+
https://github.com/kazupon/vue-i18n
7+
-->
8+
9+
<i18n>
10+
//^^^^ meta.tag.i18n.begin.html
11+
//^^^ entity.name.tag.i18n.html
12+
// ^ punctuation.definition.tag.end.html
13+
// ^ - source
14+
15+
// <- source.yaml.embedded.html
16+
</i18n>
17+
//^^^^^ meta.tag.i18n.end.html
18+
//^^^^ entity.name.tag.i18n.html
19+
// ^ punctuation.definition.tag.end.html
20+
21+
<i18n>
22+
{
23+
// ^ source.json.embedded.html meta.mapping.json punctuation.section.mapping.begin.json
24+
"en": {
25+
// ^^^^ source.json.embedded.html meta.mapping.key.json string.quoted.double.json
26+
"homePage": "Home",
27+
// ^^^^^^^^^^^^^^^^^^^^^ source.json.embedded.html meta.mapping.value.json
28+
// ^^^^^^^^^^ meta.mapping.key.json string.quoted.double.json
29+
// ^ meta.mapping.json punctuation.separator.key-value.json
30+
// ^^^^^^ meta.mapping.value.json meta.string.json string.quoted.double.json
31+
},
32+
// ^^^ source.json.embedded.html meta.mapping.value.json meta.mapping.json
33+
}
34+
// ^ source.json.embedded.html meta.mapping.json punctuation.section.mapping.end.json
35+
</i18n>
36+
//^^^^^ meta.tag.i18n.end.html
37+
//^^^^ entity.name.tag.i18n.html
38+
// ^ punctuation.definition.tag.end.html
39+
40+
<i18n>
41+
en:
42+
homePage: Home
43+
// ^^^^^^^^^^^^^^^^ source.yaml.embedded.html
44+
// ^^^^^^^^ meta.mapping.key.yaml meta.string.yaml string.unquoted
45+
// ^ meta.mapping.yaml punctuation.separator.key-value
46+
// ^^^^ meta.string.yaml string.unquoted
47+
</i18n>
48+
//^^^^^ meta.tag.i18n.end.html
49+
//^^^^ entity.name.tag.i18n.html
50+
// ^ punctuation.definition.tag.end.html
51+
52+
<i18n
53+
attr="value"
54+
//^^^^^^^^^^^^^^ meta.tag.i18n.begin.html
55+
// ^^^^^^^^^^^^ meta.attribute-with-value.html
56+
// ^^^^ entity.other.attribute-name.html
57+
// ^ punctuation.separator.key-value.html
58+
// ^^^^^^^ meta.string.html string.quoted.double.html
59+
// ^ punctuation.definition.string.begin.html
60+
// ^ punctuation.definition.string.end.html
61+
>
62+
// <- meta.tag.i18n.begin.html punctuation.definition.tag.end.html
63+
en:
64+
homePage: Home
65+
// ^^^^^^^^^^^^^^^^ source.yaml.embedded.html
66+
// ^^^^^^^^ meta.mapping.key.yaml meta.string.yaml string.unquoted
67+
// ^ meta.mapping.yaml punctuation.separator.key-value
68+
// ^^^^ meta.string.yaml string.unquoted
69+
</i18n
70+
//^^^^^ meta.tag.i18n.end.html
71+
//^^^^ entity.name.tag.i18n.html
72+
>
73+
// <- meta.tag.i18n.end.html punctuation.definition.tag.end.html

0 commit comments

Comments
 (0)