Skip to content

Commit 86f5fe2

Browse files
committed
add missing translations check, fix translations
1 parent df1f397 commit 86f5fe2

File tree

3 files changed

+84
-271
lines changed

3 files changed

+84
-271
lines changed

2.trans.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,17 @@
4040
'translator',
4141
]
4242
unused_translations = []
43+
missing_translations = []
4344

4445

4546
def translate(m):
46-
trans = translation_dict.get(m.group(1), m.group(1))
47+
s = m.group(1)
48+
trans = translation_dict.get(s, None)
4749
if not trans:
48-
trans = m.group(1)
50+
trans = s
51+
missing_translations.append(s)
4952
else:
50-
used_translations.append(m.group(1))
53+
used_translations.append(s)
5154

5255
return trans
5356

@@ -387,7 +390,7 @@ def replace_in_file(file_path, translation, base_path=BASE_PATH):
387390
'{{outliner interchange format for text only. Formatting, images and files are not included.}}',
388391
'title: "{{Export status}}"',
389392
'showError("{{Choose export type first please}}"',
390-
'throw new Error(`{{Unrecognized type ${defaultType}}}`',
393+
"throw new Error(`{{Unrecognized type}}",
391394
]
392395
replace_in_file(file_path, translation)
393396

@@ -683,8 +686,8 @@ def replace_in_file(file_path, translation, base_path=BASE_PATH):
683686
'>{{This action will create a new copy of the database and do a light anonymization on it — specifically only content of all notes will be removed, but titles and attributes will remain. Additionally, custom JS frontend/backend script notes and custom widgets will remain. This provides more context to debug the issues.}}<',
684687
'>{{You can decide yourself if you want to provide a fully or lightly anonymized database. Even fully anonymized DB is very useful, however in some cases lightly anonymized database can speed up the process of bug identification and fixing.}}<',
685688
'>{{Save lightly anonymized database}}<',
686-
'showMessage(`{{Created fully anonymized database in ${resp.anonymizedFilePath}`}}',
687-
'showMessage(`{{Created lightly anonymized database in ${resp.anonymizedFilePath}`}}',
689+
'showMessage({{`Created fully anonymized database in ${resp.anonymizedFilePath}`}}',
690+
'showMessage({{`Created lightly anonymized database in ${resp.anonymizedFilePath}`}}',
688691
'showMessage("{{Creating fully anonymized database...}}"',
689692
'showMessage("{{Creating lightly anonymized database...}}"',
690693
'showError("{{Could not create anonymized database, check backend logs for details}}"',
@@ -697,7 +700,7 @@ def replace_in_file(file_path, translation, base_path=BASE_PATH):
697700
'>{{Database Integrity Check}}<',
698701
'>{{This will check that the database is not corrupted on the SQLite level. It might take some time, depending on the DB size.}}<',
699702
'>{{Check database integrity}}<',
700-
'showMessage(`{{Integrity check failed: ${JSON.stringify(results, null, 2)}}}`',
703+
'showMessage(`{{Integrity check failed:}}',
701704
'showMessage("{{Checking database integrity...}}"',
702705
'showMessage("{{Integrity check succeeded - no problems found.}}"',
703706
]
@@ -1024,8 +1027,10 @@ def replace_in_file(file_path, translation, base_path=BASE_PATH):
10241027
'{{Underlined font}}',
10251028
'{{Font with color}}',
10261029
'{{Font with background color}}',
1030+
'{{Highlists List visibility}}',
10271031
'{{Highlights List visibility}}',
10281032
'{{You can hide the hightlights widget per-note by adding a <code>#hideHighlightWidget</code> label.}}',
1033+
'{{You can hide the highlights widget per-note by adding a <code>#hideHighlightWidget</code> label.}}',
10291034
]
10301035
replace_in_file(file_path, translation)
10311036

@@ -1173,17 +1178,17 @@ def replace_in_file(file_path, translation, base_path=BASE_PATH):
11731178

11741179
file_path = 'src/public/app/services/froca.js'
11751180
translation = [
1176-
'throw new Error(`{{Search note ${note.noteId} failed: ${searchResultNoteIds}}}`',
1181+
"`{{Search note '${note.noteId}' failed:}}",
11771182
'throw new Error("{{Empty noteId}}"',
1178-
' logError(`{{Not existing branch ${branchId}}}`',
1183+
"logError(`{{Not existing branch '${branchId}'}}`)",
11791184
' logError(`{{Could not find branchId for parent=${parentNoteId}, child=${childNoteId} since child does not exist}}`',
11801185
]
11811186
replace_in_file(file_path, translation)
11821187

11831188
file_path = 'src/public/app/services/froca_updater.js'
11841189
translation = [
1185-
'throw new Error(`{{Unknown entityName ${ec.entityName}}}`',
1186-
"""throw new Error(`{{Can't process entity ${JSON.stringify(ec)} with error ${e.message} ${e.stack}}}`""",
1190+
"throw new Error(`{{Unknown entityName '${ec.entityName}'}}`",
1191+
"""throw new Error({{`Can't process entity ${JSON.stringify(ec)} with error ${e.message} ${e.stack}`}})""",
11871192
]
11881193
replace_in_file(file_path, translation)
11891194

@@ -1350,7 +1355,7 @@ def replace_in_file(file_path, translation, base_path=BASE_PATH):
13501355

13511356
file_path = 'src/public/app/components/note_context.js'
13521357
translation = [
1353-
' logError(`{{Cannot resolve note path ${inputNotePath}}}`',
1358+
'logError({{`Cannot resolve note path ${inputNotePath}`}})',
13541359
]
13551360
replace_in_file(file_path, translation)
13561361

@@ -1360,7 +1365,7 @@ def replace_in_file(file_path, translation, base_path=BASE_PATH):
13601365
'title="{{Expand all children}}"',
13611366
'title="{{List view}}"',
13621367
'title="{{Grid view}}"',
1363-
'throw new Error({{`Invalid view type ${type}`}}',
1368+
'throw new Error(`{{Invalid view type}} ${type}`',
13641369
]
13651370
replace_in_file(file_path, translation)
13661371

@@ -1693,7 +1698,7 @@ def replace_in_file(file_path, translation, base_path=BASE_PATH):
16931698
'"{{Rename note}}"',
16941699
'>{{Rename note title to:}}<',
16951700
'>{{The given value is evaluated as JavaScript string and thus can be enriched with dynamic content via the injected }}<',
1696-
'>{{note}}<',
1701+
# '>{{note}}<',
16971702
'>{{ variable (note being renamed). Examples:}}<',
16981703
'>{{Note}}<',
16991704
'>{{ - all matched notes are renamed to "Note"}}<',
@@ -1763,7 +1768,7 @@ def replace_in_file(file_path, translation, base_path=BASE_PATH):
17631768
'>{{Convert attachment into note}}<',
17641769
'>{{Delete attachment}}<',
17651770
'"{{New attachment revision has been uploaded.}}"',
1766-
'"{{"Upload of a new attachment revision failed."}}"',
1771+
'"{{Upload of a new attachment revision failed.}}"',
17671772
'"{{Opening attachment externally is available only from the detail page, please first click on the attachment detail first and repeat the action.}}"',
17681773
'{{Are you sure you want to delete attachment}}',
17691774
"{{Attachment '${this.attachment.title}' has been deleted.}}",
@@ -2091,7 +2096,7 @@ def replace_in_file(file_path, translation, base_path=BASE_PATH):
20912096
translation = [
20922097
'title="{{Execute script}}"',
20932098
'title="{{Open Trilium API docs}}"',
2094-
'showMessage(`{{SQL Console note has been saved into ${await treeService.getNotePathTitle(notePath)}}}`',
2099+
'showMessage(`{{SQL Console note has been saved into}}',
20952100
'showMessage("{{Opening API docs...}}"',
20962101
]
20972102
replace_in_file(file_path, translation)
@@ -2238,7 +2243,7 @@ def replace_in_file(file_path, translation, base_path=BASE_PATH):
22382243
'title="{{Collapse all notes}}"',
22392244
'title="{{Expand all children}}"',
22402245
"title: '{{Book Properties}}",
2241-
'throw new Error(`{{Invalid view type ${type}}}`',
2246+
"throw new Error(`{{Invalid view type}} '${type}'`)",
22422247
' {{Collapse}}',
22432248
' {{Expand}}',
22442249
]
@@ -2354,8 +2359,8 @@ def replace_in_file(file_path, translation, base_path=BASE_PATH):
23542359
"title: '{{Search Parameters}}",
23552360
'showMessage("{{Search note has been saved into }}',
23562361
"showMessage('{{Actions have been executed.}}'",
2357-
' logError(`{{Unknown search option ${searchOptionName}}}`',
2358-
""" logError(`{{Parsing of attribute: '${actionAttr.value}' failed with error: ${e.message}}}`""",
2362+
'logError(`{{Unknown search option}}`)',
2363+
"""logError({{`Parsing of attribute: '${actionAttr.value}' failed with error: ${e.message}`}})""",
23592364
""" logError(`{{No action class for '${actionDef.name}' found.}}`""",
23602365
' {{Search & Execute actions}}',
23612366
' {{Save to note}}',
@@ -3330,14 +3335,21 @@ def replace_in_file(file_path, translation, base_path=BASE_PATH):
33303335
else:
33313336
print('no missing file, good!')
33323337
print('=====================================')
3333-
unused_translations = [key for key in translation_dict if key not in used_translations]
3338+
unused_translations = [key for key in translation_dict if key and key not in used_translations]
33343339
if unused_translations:
33353340
print('unused_translations! \n')
33363341
for x in unused_translations:
33373342
print(x)
33383343
else:
33393344
print('no unused translation, good!')
33403345
print('=====================================')
3346+
if missing_translations:
3347+
print('missing_translations! \n')
3348+
for x in missing_translations:
3349+
print(x)
3350+
else:
3351+
print('no missing translation, good!')
3352+
print('=====================================')
33413353

33423354
# 尝试删除electron的缓存, 避免代码修改不生效的问题
33433355
# try delete electron cache, avoid code change does not take effect

0 commit comments

Comments
 (0)