mirror of
https://github.com/imputnet/helium.git
synced 2026-10-19 01:39:56 -05:00
i18n: fix "add shortcut" string collision (#1891)
This commit is contained in:
4 files changed
+28
-12
No files matched your search
@@ -7,6 +7,7 @@ String extraction from Helium patches for translation.
|
||||
|
||||
import subprocess
|
||||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
from third_party import unidiff
|
||||
@@ -17,6 +18,12 @@ PLATFORMS = ("windows", "macos", "linux")
|
||||
REPO_URL = "https://github.com/imputnet/helium-{platform}.git"
|
||||
|
||||
|
||||
def get_xml_attr(text, attr):
|
||||
"""Extract an XML attribute from an opening tag."""
|
||||
match = re.search(rf'{attr}="([^"]*)"', text)
|
||||
return match.group(1) if match else None
|
||||
|
||||
|
||||
def prep_platform_repos(platforms_dir):
|
||||
"""Clone and update platform repos into the given directory."""
|
||||
platforms_dir.mkdir(parents=True, exist_ok=True)
|
||||
@@ -71,7 +78,7 @@ def extract_strings_from_hunk(hunk):
|
||||
- broken chunks of untouched, pre-existing units
|
||||
- units that were added in a different patch (avoiding duplication)
|
||||
"""
|
||||
name, message, desc = None, '', None
|
||||
name, message, desc, meaning = None, '', None, None
|
||||
meta_acc = ''
|
||||
had_any_additive = False
|
||||
|
||||
@@ -87,15 +94,16 @@ def extract_strings_from_hunk(hunk):
|
||||
meta_acc += line
|
||||
elif line.startswith('</message>'):
|
||||
if name and message and had_any_additive:
|
||||
yield name, desc, message
|
||||
name, message, desc = None, '', None
|
||||
yield name, desc, meaning, message
|
||||
name, message, desc, meaning = None, '', None, None
|
||||
had_any_additive = False
|
||||
elif name:
|
||||
message += line
|
||||
|
||||
if meta_acc and line.endswith('>'):
|
||||
name = meta_acc.split('name="')[1].split('"')[0]
|
||||
desc = meta_acc.split('desc="')[1].split('"')[0]
|
||||
name = get_xml_attr(meta_acc, 'name')
|
||||
desc = get_xml_attr(meta_acc, 'desc')
|
||||
meaning = get_xml_attr(meta_acc, 'meaning')
|
||||
meta_acc = ''
|
||||
|
||||
had_any_additive |= bool(name) and is_additive
|
||||
@@ -105,16 +113,19 @@ def extract_strings(repo_root, platforms_dir):
|
||||
"""Generate strings to be translated for all grit strings in patches."""
|
||||
for patch in get_relevant_patches(repo_root, platforms_dir):
|
||||
for hunk in patch:
|
||||
for name, desc, message in extract_strings_from_hunk(hunk):
|
||||
for name, desc, meaning, message in extract_strings_from_hunk(hunk):
|
||||
context = namesub.replace_text(desc)[0]
|
||||
message = namesub.replace_text(message)[0]
|
||||
|
||||
yield {
|
||||
entry = {
|
||||
'name': name,
|
||||
'source': patch.path,
|
||||
'context': context,
|
||||
'message': message,
|
||||
}
|
||||
if meaning:
|
||||
entry['meaning'] = namesub.replace_text(meaning)[0]
|
||||
entry['message'] = message
|
||||
yield entry
|
||||
|
||||
|
||||
def run(args, repo_root):
|
||||
|
||||
@@ -633,6 +633,7 @@
|
||||
"name": "IDS_SETTINGS_SHORTCUTS_ADD_DIALOG_TITLE",
|
||||
"source": "chrome/app/settings_strings.grdp",
|
||||
"context": "Title of the dialog for recording a new browser keyboard shortcut.",
|
||||
"meaning": "Dialog title for adding a keyboard shortcut in Settings.",
|
||||
"message": "Add shortcut"
|
||||
},
|
||||
{
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
+ <message name="IDS_SETTINGS_SHORTCUTS_RESET_ALL" desc="Button label for resetting all browser command shortcuts.">
|
||||
+ Reset all to defaults
|
||||
+ </message>
|
||||
+ <message name="IDS_SETTINGS_SHORTCUTS_ADD_DIALOG_TITLE" desc="Title of the dialog for recording a new browser keyboard shortcut.">
|
||||
+ <message name="IDS_SETTINGS_SHORTCUTS_ADD_DIALOG_TITLE" desc="Title of the dialog for recording a new browser keyboard shortcut." meaning="Dialog title for adding a keyboard shortcut in Settings.">
|
||||
+ Add shortcut
|
||||
+ </message>
|
||||
+ <message name="IDS_SETTINGS_SHORTCUTS_RESET_DIALOG_DESCRIPTION" desc="Description of the confirmation dialog shown when user resets their shortcuts to default.">
|
||||
|
||||
+7
-3
@@ -25,9 +25,13 @@ SOURCE_PATH = I18N_DIR / 'source.gen.json'
|
||||
TRANSLATIONS_DIR = I18N_DIR / 'translations'
|
||||
|
||||
|
||||
def get_id(name, context, text):
|
||||
def get_id(name, context, text, meaning):
|
||||
"""Compute the fingerprint ID for a GRD message element."""
|
||||
message = xml.fromstring(f'<message name="{name}" desc="{context}">{text}</message>')
|
||||
message = xml.fromstring(f'<message>{text}</message>')
|
||||
message.set('name', name)
|
||||
message.set('desc', context)
|
||||
if meaning:
|
||||
message.set('meaning', meaning)
|
||||
return namesub.compute_fp(message)
|
||||
|
||||
|
||||
@@ -142,7 +146,7 @@ def merge_into_xtb(xtb_path, source_entries, trans_by_key):
|
||||
trans = trans_by_key.get(key)
|
||||
if not trans:
|
||||
continue
|
||||
msg_id = get_id(src['name'], src['context'], src['message'])
|
||||
msg_id = get_id(src['name'], src['context'], src['message'], src.get('meaning'))
|
||||
if msg_id in seen_ids:
|
||||
continue
|
||||
seen_ids.add(msg_id)
|
||||
|
||||
Reference in new issue
Block a user