Skip to content

Commit 5c21187

Browse files
committed
update translate
1 parent f2e59f3 commit 5c21187

File tree

20 files changed

+3759
-2423
lines changed

20 files changed

+3759
-2423
lines changed
25.2 KB
Binary file not shown.
24.2 KB
Binary file not shown.
15.2 KB
Binary file not shown.

astroquery_cli/main.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,27 @@ def setup_subcommands():
7575
# Restore astroquery log level after import
7676
logging.getLogger('astroquery').setLevel(logging.NOTSET)
7777

78-
app.add_typer(alma_cli.get_app(), name="alma")
79-
app.add_typer(esasky_cli.get_app(), name="esasky")
80-
app.add_typer(gaia_cli.get_app(), name="gaia")
81-
app.add_typer(irsa_cli.get_app(), name="irsa")
82-
app.add_typer(jpl_cli.get_app(), name="jpl") # Updated for jpl
8378
app.add_typer(mast_cli.get_app(), name="mast")
84-
app.add_typer(ads_cli.get_app(), name="ads")
85-
app.add_typer(ned_cli.get_app(), name="ned")
86-
app.add_typer(simbad_cli.get_app(), name="simbad", help=builtins._("Query the SIMBAD astronomical database. (sim)"))
87-
app.add_typer(simbad_cli.get_app(), name="sim") # Alias for simbad
88-
app.add_typer(splatalogue_cli.get_app(), name="splatalogue", help=builtins._("Query the Splatalogue spectral line database. (spl)"))
89-
app.add_typer(splatalogue_cli.get_app(), name="spl") # Alias for splatalogue
9079
app.add_typer(vizier_cli.get_app(), name="vizier", help=builtins._("Query the VizieR astronomical catalog database. (viz)"))
9180
app.add_typer(vizier_cli.get_app(), name="viz") # Alias for vizier
81+
app.add_typer(simbad_cli.get_app(), name="simbad", help=builtins._("Query the SIMBAD astronomical database. (sim)"))
82+
app.add_typer(simbad_cli.get_app(), name="sim") # Alias for simbad
83+
app.add_typer(jpl_cli.get_app(), name="jpl") # Updated for jpl
84+
app.add_typer(exoplanet_cli.get_app(), name="exoplanet", help=builtins._("Query the NASA Exoplanet Archive. (exo)"))
85+
app.add_typer(exoplanet_cli.get_app(), name="exo") # Alias for exoplanet
9286
app.add_typer(heasarc_cli.get_app(), name="heasarc", help=builtins._("Query the HEASARC database. (hea)"))
9387
app.add_typer(heasarc_cli.get_app(), name="hea") # Alias for heasarc
94-
app.add_typer(sdss_cli.get_app(), name="sdss")
88+
app.add_typer(gaia_cli.get_app(), name="gaia")
89+
app.add_typer(alma_cli.get_app(), name="alma")
90+
app.add_typer(irsa_cli.get_app(), name="irsa")
91+
app.add_typer(sdss_cli.get_app(builtins._), name="sdss")
92+
app.add_typer(ned_cli.get_app(), name="ned")
9593
app.add_typer(eso_cli.get_app(), name="eso")
96-
app.add_typer(nist_cli.get_app(), name="nist")
97-
app.add_typer(exoplanet_cli.get_app(), name="exoplanet", help=builtins._("Query the NASA Exoplanet Archive. (exo)"))
98-
app.add_typer(exoplanet_cli.get_app(), name="exo") # Alias for exoplanet
94+
app.add_typer(esasky_cli.get_app(), name="esasky")
95+
app.add_typer(nist_cli.get_app(builtins._), name="nist")
96+
app.add_typer(splatalogue_cli.get_app(), name="splatalogue", help=builtins._("Query the Splatalogue spectral line database. (spl)"))
97+
app.add_typer(splatalogue_cli.get_app(), name="spl") # Alias for splatalogue
98+
app.add_typer(ads_cli.get_app(), name="ads")
9999

100100
@app.callback()
101101
def main_callback(

astroquery_cli/modules/nist_cli.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
from astroquery_cli.common_options import setup_debug_context
1919
from astroquery_cli.debug import debug
2020

21-
def get_app():
22-
import builtins
23-
_ = builtins._
21+
def get_app(_: callable):
2422
app = typer.Typer(
2523
name="nist",
26-
help=builtins._("Query the NIST Atomic Spectra Database."),
24+
help=_("Query the NIST Atomic Spectra Database."),
2725
invoke_without_command=True,
2826
no_args_is_help=False
2927
)
@@ -34,43 +32,43 @@ def nist_callback(
3432
ctx: typer.Context,
3533
query_string: Optional[str] = typer.Argument(
3634
None,
37-
help=builtins._("Primary query input: wavelength range (e.g., '2000 3000') or line name (e.g., 'Fe II').")
35+
help=_("Primary query input: wavelength range (e.g., '2000 3000') or line name (e.g., 'Fe II').")
3836
),
3937
minwav: Optional[float] = typer.Option(
4038
None,
41-
help=builtins._("Explicit minimum wavelength (e.g., 2000). Overrides any wavelength range parsed from 'query_string'. "
39+
help=_("Explicit minimum wavelength (e.g., 2000). Overrides any wavelength range parsed from 'query_string'. "
4240
"Can be combined with '--linename'.")
4341
),
4442
maxwav: Optional[float] = typer.Option(
4543
None,
46-
help=builtins._("Explicit maximum wavelength (e.g., 3000). Overrides any wavelength range parsed from 'query_string'. "
44+
help=_("Explicit maximum wavelength (e.g., 3000). Overrides any wavelength range parsed from 'query_string'. "
4745
"Can be combined with '--linename'.")
4846
),
4947
linename: Optional[str] = typer.Option(
5048
None,
51-
help=builtins._("Explicit line name (e.g., 'Fe II', 'H I'). Overrides any line name parsed from 'query_string'. "
49+
help=_("Explicit line name (e.g., 'Fe II', 'H I'). Overrides any line name parsed from 'query_string'. "
5250
"Can be combined with explicit '--minwav' and '--maxwav' for a specific range.")
5351
),
5452
output_file: Optional[str] = common_output_options["output_file"],
5553
output_format: Optional[str] = common_output_options["output_format"],
5654
max_rows_display: int = typer.Option(
57-
25, help=builtins._("Maximum number of rows to display. Use -1 for all rows.")
55+
25, help=_("Maximum number of rows to display. Use -1 for all rows.")
5856
),
5957
show_all_columns: bool = typer.Option(
60-
False, "--show-all-cols", help=builtins._("Show all columns in the output table.")
58+
False, "--show-all-cols", help=_("Show all columns in the output table.")
6159
),
62-
test: bool = typer.Option(False, "--test", "-t", help=builtins._("Enable test mode and print elapsed time.")),
60+
test: bool = typer.Option(False, "--test", "-t", help=_("Enable test mode and print elapsed time.")),
6361
debug_flag: bool = typer.Option( # Renamed to avoid conflict with imported debug
6462
False,
6563
"--debug", # Removed -t to avoid conflict with --test
66-
help=builtins._("Enable debug mode with verbose output."),
64+
help=_("Enable debug mode with verbose output."),
6765
envvar="AQC_DEBUG"
6866
),
6967
verbose: bool = typer.Option(
7068
False,
7169
"-v",
7270
"--verbose",
73-
help=builtins._("Enable verbose output.")
71+
help=_("Enable verbose output.")
7472
)
7573
):
7674
setup_debug_context(ctx, debug_flag, verbose)

astroquery_cli/modules/sdss_cli.py

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,21 @@
1818
from astroquery_cli.common_options import setup_debug_context
1919
from astroquery_cli.debug import debug
2020

21-
def get_app():
22-
import builtins
23-
_ = builtins._
21+
def get_app(_: callable):
2422
app = typer.Typer(
2523
name="sdss",
26-
help=builtins._(
27-
"Query the Sloan Digital Sky Survey database.\n\n"
28-
"Perform a query on SDSS. You must provide parameters for exactly one of the following query types:\n\n"
29-
" 1. Cone Search:\n"
30-
" --ra <RA> --dec <DEC> --radius <RADIUS>\n"
31-
" (e.g., --ra '10.5 deg' --dec '20.1 deg' --radius '2 arcmin')\n\n"
32-
" 2. Spectroscopic Object ID Search:\n"
33-
" --specobjid <ID> [--objtype <TYPE>]\n"
34-
" (e.g., --specobjid 2634622337315530752 --objtype 'GALAXY')\n\n"
35-
" 3. Fiber ID Search:\n"
36-
" --plate <PLATE> --mjd <MJD> --fiberid <FIBERID> [--objtype <TYPE>]\n"
37-
" (e.g., --plate 123 --mjd 51608 --fiberid 1)"
24+
help=(
25+
_("Query the Sloan Digital Sky Survey database.") + "\n\n" +
26+
_("Perform a query on SDSS. You must provide parameters for exactly one of the following query types:") + "\n\n" +
27+
_(" 1. Cone Search:") + "\n" +
28+
_(" --ra <RA> --dec <DEC> --radius <RADIUS>") + "\n" +
29+
_(" (e.g., --ra '10.5 deg' --dec '20.1 deg' --radius '2 arcmin')") + "\n\n" +
30+
_(" 2. Spectroscopic Object ID Search:") + "\n" +
31+
_(" --specobjid <ID> [--objtype <TYPE>]") + "\n" +
32+
_(" (e.g., --specobjid 2634622337315530752 --objtype 'GALAXY')") + "\n\n" +
33+
_(" 3. Fiber ID Search:") + "\n" +
34+
_(" --plate <PLATE> --mjd <MJD> --fiberid <FIBERID> [--objtype <TYPE>]") + "\n" +
35+
_(" (e.g., --plate 123 --mjd 51608 --fiberid 1)")
3836
),
3937
invoke_without_command=True,
4038
no_args_is_help=False
@@ -48,30 +46,30 @@ def sdss_callback(
4846
False,
4947
"-t",
5048
"--debug",
51-
help=builtins._("Enable debug mode with verbose output."),
49+
help=_("Enable debug mode with verbose output."),
5250
envvar="AQC_DEBUG"
5351
),
5452
verbose: bool = typer.Option(
5553
False,
5654
"-v",
5755
"--verbose",
58-
help=builtins._("Enable verbose output.")
56+
help=_("Enable verbose output.")
5957
),
60-
ra: Optional[str] = typer.Option(None, help=builtins._("Right Ascension (e.g., '10.5 deg', '0h42m30s'). Required for cone search.")),
61-
dec: Optional[str] = typer.Option(None, help=builtins._("Declination (e.g., '20.1 deg', '+41d12m0s'). Required for cone search.")),
62-
radius: Optional[str] = typer.Option(None, help=builtins._("Search radius (e.g., '0.5 deg', '2 arcmin'). Max 3 arcmin. Required for cone search.")),
63-
objtype: Optional[str] = typer.Option(None, help=builtins._("Object type (e.g., 'STAR', 'GALAXY', 'QSO'). Note: This parameter is only applicable for queries using specobjid or plate/mjd/fiberid, not for cone searches.")),
64-
specobjid: Optional[int] = typer.Option(None, help=builtins._("Spectroscopic object ID. Required for specobjid search.")),
65-
plate: Optional[int] = typer.Option(None, help=builtins._("Plate number for spectroscopic data. Required for fiber ID search.")),
66-
mjd: Optional[int] = typer.Option(None, help=builtins._("Modified Julian Date for spectroscopic data. Required for fiber ID search.")),
67-
fiberid: Optional[int] = typer.Option(None, help=builtins._("Fiber ID for spectroscopic data. Required for fiber ID search.")),
58+
ra: Optional[str] = typer.Option(None, help=_("Right Ascension (e.g., '10.5 deg', '0h42m30s'). Required for cone search.")),
59+
dec: Optional[str] = typer.Option(None, help=_("Declination (e.g., '20.1 deg', '+41d12m0s'). Required for cone search.")),
60+
radius: Optional[str] = typer.Option(None, help=_("Search radius (e.g., '0.5 deg', '2 arcmin'). Max 3 arcmin. Required for cone search.")),
61+
objtype: Optional[str] = typer.Option(None, help=_("Object type (e.g., 'STAR', 'GALAXY', 'QSO'). Note: This parameter is only applicable for queries using specobjid or plate/mjd/fiberid, not for cone searches.")),
62+
specobjid: Optional[int] = typer.Option(None, help=_("Spectroscopic object ID. Required for specobjid search.")),
63+
plate: Optional[int] = typer.Option(None, help=_("Plate number for spectroscopic data. Required for fiber ID search.")),
64+
mjd: Optional[int] = typer.Option(None, help=_("Modified Julian Date for spectroscopic data. Required for fiber ID search.")),
65+
fiberid: Optional[int] = typer.Option(None, help=_("Fiber ID for spectroscopic data. Required for fiber ID search.")),
6866
output_file: Optional[str] = common_output_options["output_file"],
6967
output_format: Optional[str] = common_output_options["output_format"],
7068
max_rows_display: int = typer.Option(
71-
25, help=builtins._("Maximum number of rows to display. Use -1 for all rows.")
69+
25, help=_("Maximum number of rows to display. Use -1 for all rows.")
7270
),
7371
show_all_columns: bool = typer.Option(
74-
False, "--show-all-cols", help=builtins._("Show all columns in the output table.")
72+
False, "--show-all-cols", help=_("Show all columns in the output table.")
7573
),
7674
):
7775
setup_debug_context(ctx, debug, verbose)

locales/backfill_translated.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import polib
2+
import os
3+
import sys
4+
5+
def backfill_translated(po_file_path, untranslated_tmp_path):
6+
"""
7+
Backfills translations from a .tmp file into a .po file using polib.
8+
Also clears fuzzy flags for updated entries.
9+
"""
10+
try:
11+
po = polib.pofile(po_file_path)
12+
except Exception as e:
13+
print(f"Error reading PO file {po_file_path}: {e}", file=sys.stderr)
14+
return
15+
16+
# Read translations from the .tmp file
17+
translations = {}
18+
try:
19+
with open(untranslated_tmp_path, 'r', encoding='utf-8') as f:
20+
for line in f:
21+
# Do not strip the entire line, as msgid might have leading/trailing whitespace or newlines
22+
if line.startswith('/') or not line.strip(): # Skip comments and empty lines
23+
continue
24+
parts = line.split('|||', 1)
25+
if len(parts) == 2:
26+
msgid = parts[0]
27+
msgstr = parts[1].strip()
28+
translations[msgid] = msgstr
29+
except Exception as e:
30+
print(f"Error reading untranslated .tmp file {untranslated_tmp_path}: {e}", file=sys.stderr)
31+
return
32+
33+
updated_count = 0
34+
for entry in po:
35+
# Normalize the msgid from the .po file for comparison
36+
# Remove leading newline if it's a multi-line string starting with ""\n"..."
37+
normalized_po_msgid = entry.msgid
38+
if normalized_po_msgid.startswith('\n') and len(normalized_po_msgid) > 1 and normalized_po_msgid[1] != '\n':
39+
normalized_po_msgid = normalized_po_msgid[1:]
40+
41+
if not entry.obsolete:
42+
if normalized_po_msgid in translations:
43+
new_msgstr = translations[normalized_po_msgid]
44+
if entry.msgstr != new_msgstr:
45+
entry.msgstr = new_msgstr
46+
# Clear fuzzy flag if it was updated
47+
if 'fuzzy' in entry.flags:
48+
entry.flags.remove('fuzzy')
49+
updated_count += 1
50+
elif 'fuzzy' in entry.flags:
51+
# If msgstr is already correct but still fuzzy, clear fuzzy flag
52+
entry.flags.remove('fuzzy')
53+
updated_count += 1
54+
55+
56+
if updated_count > 0:
57+
try:
58+
po.save()
59+
print(f"Updated {updated_count} entries in {po_file_path}")
60+
except Exception as e:
61+
print(f"Error saving PO file {po_file_path}: {e}", file=sys.stderr)
62+
else:
63+
print(f"No updates needed for {po_file_path}")
64+
65+
66+
if __name__ == "__main__":
67+
if len(sys.argv) != 3:
68+
print("Usage: python backfill_translated.py <po_file_path> <untranslated_tmp_path>", file=sys.stderr)
69+
sys.exit(1)
70+
71+
po_file = sys.argv[1]
72+
untranslated_tmp_file = sys.argv[2]
73+
backfill_translated(po_file, untranslated_tmp_file)

locales/check-update.sh

Lines changed: 6 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ set -e
44
LOCALES_DIR="$(dirname "$0")"
55
DOMAIN="messages"
66

7+
# First, extract all untranslated entries into .tmp files
8+
echo "Extracting latest untranslated entries into .tmp files..."
9+
sh "$LOCALES_DIR/extract-untranslated.sh"
10+
echo "Finished extracting untranslated entries."
11+
712
for tmp in "$LOCALES_DIR"/untranslated_*.tmp; do
813
[ -f "$tmp" ] || continue
914
lang=$(echo "$tmp" | sed -E 's/.*untranslated_([^.]+)\.tmp/\1/')
@@ -15,110 +20,7 @@ for tmp in "$LOCALES_DIR"/untranslated_*.tmp; do
1520

1621
cp "$po" "$po.bak"
1722

18-
awk -v TMP="$tmp" '
19-
function trim(s) { sub(/^[ \t\r\n]+/, "", s); sub(/[ \t\r\n]+$/, "", s); return s }
20-
function extract_vars(str, arr, n, i, m) {
21-
n = split(str, arr, /\{[a-zA-Z0-9_]+\}/)
22-
m = match(str, /\{[a-zA-Z0-9_]+\}/)
23-
delete arr
24-
i = 0
25-
while (match(str, /\{[a-zA-Z0-9_]+\}/)) {
26-
arr[++i] = substr(str, RSTART, RLENGTH)
27-
str = substr(str, RSTART + RLENGTH)
28-
}
29-
return i
30-
}
31-
function sync_vars(msgid, msgstr, vars_id, vars_str, i, j, out, p) {
32-
split("", vars_id)
33-
split("", vars_str)
34-
extract_vars(msgid, vars_id)
35-
extract_vars(msgstr, vars_str)
36-
out = msgstr
37-
if (length(vars_id) > 0 && length(vars_str) == 0) {
38-
sub(/"$/, " " vars_id[1] "\"", out)
39-
for (i=2; i<=length(vars_id); i++) out = substr(out,1,length(out)-2) " " vars_id[i] "\"\n"
40-
return out
41-
}
42-
if (length(vars_id) > 0) {
43-
j = 1
44-
out = msgstr
45-
while (match(out, /\{[a-zA-Z0-9_]+\}/)) {
46-
if (j <= length(vars_id)) {
47-
out = substr(out,1,RSTART-1) vars_id[j] substr(out,RSTART+RLENGTH)
48-
} else {
49-
out = substr(out,1,RSTART-1) substr(out,RSTART+RLENGTH)
50-
}
51-
j++
52-
}
53-
for (p=j; p<=length(vars_id); p++) {
54-
sub(/"$/, " " vars_id[p] "\"", out)
55-
}
56-
return out
57-
}
58-
gsub(/\{[a-zA-Z0-9_]+\}/, "", out)
59-
return out
60-
}
61-
BEGIN {
62-
while ((getline < TMP) > 0) {
63-
if ($0 ~ /^\//) continue
64-
split($0, arr, /\|\|\|/)
65-
key = trim(arr[1])
66-
val = trim(arr[2])
67-
untranslated[key] = val
68-
}
69-
close(TMP)
70-
msgid = ""; msgstr = ""; inmsgid = 0; inmsgstr = 0; lines = ""
71-
}
72-
/^msgid / {
73-
inmsgid = 1; inmsgstr = 0
74-
msgid = substr($0,8,length($0)-8)
75-
lines = $0 "\n"
76-
next
77-
}
78-
/^msgstr / {
79-
inmsgid = 0; inmsgstr = 1
80-
msgstr = substr($0,9,length($0)-9)
81-
if (msgid in untranslated && untranslated[msgid] != "") {
82-
n = split(untranslated[msgid], arr, /\n/)
83-
if (n == 1) {
84-
fixed = sync_vars(msgid, "msgstr \"" arr[1] "\"\n")
85-
lines = lines fixed
86-
} else {
87-
lines = lines "msgstr \"\"\n"
88-
for (i = 1; i <= n; i++) {
89-
if (arr[i] != "") {
90-
fixed = sync_vars(msgid, "\"" arr[i] "\"\n")
91-
lines = lines fixed
92-
}
93-
}
94-
}
95-
} else {
96-
lines = lines $0 "\n"
97-
}
98-
print lines
99-
msgid = ""; msgstr = ""; lines = ""
100-
next
101-
}
102-
/^"/ {
103-
if (inmsgid) {
104-
msgid = msgid substr($0,2,length($0)-2)
105-
}
106-
if (inmsgstr) {
107-
msgstr = msgstr substr($0,2,length($0)-2)
108-
}
109-
lines = lines $0 "\n"
110-
next
111-
}
112-
{
113-
lines = lines $0 "\n"
114-
if ($0 == "") {
115-
print lines
116-
msgid = ""; msgstr = ""; inmsgid = 0; inmsgstr = 0; lines = ""
117-
}
118-
}
119-
' "$po.bak" > "$po"
120-
121-
msgattrib --clear-fuzzy "$po" -o "$po"
23+
poetry run python "$LOCALES_DIR/backfill_translated.py" "$po" "$tmp"
12224
echo "Updated: $po"
12325
done
12426

0 commit comments

Comments
 (0)