Skip to content

Commit c079457

Browse files
authored
Replace judgment of localeKey with common method
1 parent 1138c0c commit c079457

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

lib/rules/key-format-style.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function create(context: RuleContext): RuleListener {
6363
upper?: KeyStack
6464
}
6565
let keyStack: KeyStack = {
66-
inLocale: targetLocaleMessage.localeKey === 'file'
66+
inLocale: targetLocaleMessage.isResolvedLocaleByFileName()
6767
}
6868
return {
6969
JSONProperty(node: JSONAST.JSONProperty) {
@@ -110,7 +110,7 @@ function create(context: RuleContext): RuleListener {
110110
upper?: KeyStack
111111
}
112112
let keyStack: KeyStack = {
113-
inLocale: targetLocaleMessage.localeKey === 'file'
113+
inLocale: targetLocaleMessage.isResolvedLocaleByFileName()
114114
}
115115
function withinKey(node: YAMLAST.YAMLNode) {
116116
for (const keyNode of yamlKeyNodes) {

lib/rules/no-duplicate-keys-in-locale.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function create(context: RuleContext): RuleListener {
4747
targetLocaleMessage: LocaleMessage,
4848
otherLocaleMessages: LocaleMessage[]
4949
): PathStack {
50-
if (targetLocaleMessage.localeKey === 'file') {
50+
if (targetLocaleMessage.isResolvedLocaleByFileName()) {
5151
const locale = targetLocaleMessage.locales[0]
5252
return createInitLocalePathStack(locale, otherLocaleMessages)
5353
} else {

lib/rules/no-missing-keys-in-other-locales.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function create(context: RuleContext): RuleListener {
115115
}[]
116116
}
117117
let keyStack: KeyStack
118-
if (targetLocaleMessage.localeKey === 'file') {
118+
if (targetLocaleMessage.isResolvedLocaleByFileName()) {
119119
const locale = targetLocaleMessage.locales[0]
120120
keyStack = {
121121
locale,

lib/utils/locale-messages.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,15 @@ export abstract class LocaleMessage {
114114
return (this._locales = [])
115115
}
116116

117+
isResolvedLocaleByFileName() {
118+
return this.localeKey === 'file' || this.localeKey === 'path'
119+
}
120+
117121
/**
118122
* Gets messages for the given locale.
119123
*/
120124
getMessagesFromLocale(locale: string): I18nLocaleMessageDictionary {
121-
if (this.localeKey === 'file' || this.localeKey === 'path') {
125+
if (this.isResolvedLocaleByFileName()) {
122126
if (!this.locales.includes(locale)) {
123127
return {}
124128
}

0 commit comments

Comments
 (0)