Skip to content

Commit 15ebdcd

Browse files
committed
fix source language missing in localizations
1 parent 44d8fa5 commit 15ebdcd

4 files changed

Lines changed: 35 additions & 2 deletions

File tree

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"program": "main.go",
1313
"args": [
1414
"baidu",
15-
"-i", "${workspaceFolder}/example.xcstrings",
15+
"-i", "${workspaceFolder}/example2.xcstrings",
1616
"--app-id", "${env:BAIDU_APP_ID}",
1717
"--app-secret", "${env:BAIDU_APP_SECRET}",
1818
"-s", "en",

example2.xcstrings

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"sourceLanguage" : "en",
3+
"strings" : {
4+
"" : {
5+
"shouldTranslate" : false
6+
},
7+
"🎁 Subscribe Premium Plan to Unlock All Features" : {
8+
"localizations" : {
9+
"de" : {
10+
"stringUnit" : {
11+
"state" : "translated",
12+
"value" : "🎁 Premium-Plan abonnieren, um alle Funktionen zu entsperren"
13+
}
14+
},
15+
"zh-Hans" : {
16+
"stringUnit" : {
17+
"state" : "translated",
18+
"value" : "🎁 订阅高级会员以解锁全部功能"
19+
}
20+
}
21+
}
22+
}
23+
},
24+
"version" : "1.0"
25+
}

internal/model/model.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ type XCStrings struct {
1616

1717
// StringEntry represents a single string entry with its localizations
1818
type StringEntry struct {
19-
Localizations map[string]Localization `json:"localizations"`
19+
Localizations map[string]Localization `json:"localizations,omitempty"`
20+
ShouldTranslate *bool `json:"shouldTranslate,omitempty"`
2021
}
2122

2223
// Localization represents a localization for a specific language

internal/translator/translator.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,19 @@ func CreateTranslationRequests(xcstrings *model.XCStrings, targetLanguages []str
101101
var requests []model.TranslationRequest
102102

103103
for key, entry := range xcstrings.Strings {
104+
if entry.ShouldTranslate != nil && *entry.ShouldTranslate == false {
105+
continue
106+
}
104107
// Get source text (from source language)
105108
sourceText := ""
106109
if sourceLangEntry, ok := entry.Localizations[xcstrings.SourceLanguage]; ok {
107110
sourceText = sourceLangEntry.StringUnit.Value
108111
}
109112

113+
if key != "" && sourceText == "" {
114+
sourceText = key
115+
}
116+
110117
if sourceText == "" {
111118
continue
112119
}

0 commit comments

Comments
 (0)