mirror of
https://salsa.debian.org/dskoll/remind.git
synced 2026-04-17 14:59:20 +02:00
Implement the "TRANSLATE" command to translate just one string;
rename "JSONTRANSLATE" to "TRANSLATE_DUMP"
This commit is contained in:
@@ -414,18 +414,33 @@ The value of the \fBqueue\fR key is an array of JSON objects, each
|
||||
representing a queued reminder.
|
||||
|
||||
.TP
|
||||
JSONTRANSLATE
|
||||
TRANSLATE Any string goes here
|
||||
Returns the translation of "Any string goes here" according to \fBRemind\fR's
|
||||
translation table. Note that there must be exactly one space after
|
||||
TRANSLATE and before the string you wish to translate. The JSON object
|
||||
that results from "TRANSLATE New Moon" might look like this:
|
||||
.nf
|
||||
|
||||
{"response":"translate","translation":{"New Moon":"Nieuwe maan"},"command":"TRANSLATE"}
|
||||
|
||||
.fi
|
||||
As you see, the value of the \fBtranslation\fR key is an object whose
|
||||
key is the original text and value is the translated text. A
|
||||
front-end can use TRANSLATE do its own localization; for example,
|
||||
TkRemind uses it to localize the moon phase popup window for the
|
||||
SPECIAL MOON display.
|
||||
|
||||
.TP
|
||||
TRANSLATE_DUMP
|
||||
Returns the contents of the translation table. The JSON object looks
|
||||
like this:
|
||||
.nf
|
||||
|
||||
{"response":"translate","table":{...},"command":"JSONTRANSLATE"}
|
||||
{"response":"translate_dump","table":{...},"command":"TRANSLATE_DUMP"}
|
||||
|
||||
.fi
|
||||
The value of the \fBtable\fR key is a dictionary of original-to-translated
|
||||
strings. A front-end can use the table to do its own localization;
|
||||
for example, TkRemind uses it to localize the moon phase popup window
|
||||
for the SPECIAL MOON display.
|
||||
strings.
|
||||
|
||||
.TP
|
||||
DEL \fIqid\fR
|
||||
|
||||
@@ -699,8 +699,12 @@ proc DoQueue {} {
|
||||
}
|
||||
|
||||
proc DoTranslate {} {
|
||||
# Get just the translations we can use
|
||||
global DaemonFile
|
||||
puts $DaemonFile "JSONTRANSLATE"
|
||||
puts $DaemonFile "TRANSLATE New Moon"
|
||||
puts $DaemonFile "TRANSLATE Full Moon"
|
||||
puts $DaemonFile "TRANSLATE First Quarter"
|
||||
puts $DaemonFile "TRANSLATE Last Quarter"
|
||||
flush $DaemonFile
|
||||
}
|
||||
|
||||
@@ -2835,17 +2839,17 @@ proc sort_q { a b } {
|
||||
}
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# PopulateTranslations
|
||||
# AddTranslation
|
||||
# Arguments:
|
||||
# table -- the translation table from Remind
|
||||
# obj - a dictionary of the form old:new
|
||||
# Returns:
|
||||
# nothing
|
||||
# Description:
|
||||
# Populates the Translations dict object
|
||||
# Updates the Translations dict object
|
||||
#---------------------------------------------------------------------------
|
||||
proc PopulateTranslations { table } {
|
||||
proc AddTranslation { obj } {
|
||||
global Translations
|
||||
set Translations $table
|
||||
set Translations [dict merge $Translations $obj]
|
||||
ScheduleUpdateForChanges
|
||||
}
|
||||
|
||||
@@ -2887,8 +2891,7 @@ proc DaemonReadable { file } {
|
||||
set response [dict get $obj response]
|
||||
switch -- $response {
|
||||
"translate" {
|
||||
set table [dict get $obj table]
|
||||
PopulateTranslations $table
|
||||
AddTranslation [dict get $obj translation]
|
||||
}
|
||||
"queued" {
|
||||
set n [dict get $obj nqueued]
|
||||
|
||||
24
src/queue.c
24
src/queue.c
@@ -942,19 +942,33 @@ static void ServerWait(struct timeval *sleep_tv)
|
||||
printf("NOTE ENDJSONQUEUE\n");
|
||||
}
|
||||
fflush(stdout);
|
||||
} else if (!strcmp(cmdLine, "JSONTRANSLATE\n")) {
|
||||
} else if (DaemonJSON && !strncmp(cmdLine, "TRANSLATE ", 10)) {
|
||||
/* Cut off the trailing "\n" */
|
||||
if (*(cmdLine + strlen(cmdLine)-1) == '\n') {
|
||||
*(cmdLine + strlen(cmdLine)-1) = 0;
|
||||
}
|
||||
printf("{");
|
||||
PrintJSONKeyPairString("response", "translate");
|
||||
printf("\"translation\":{\"");
|
||||
PrintJSONString(cmdLine+10);
|
||||
printf("\":\"");
|
||||
PrintJSONString(t(cmdLine+10));
|
||||
printf("\"},");
|
||||
printf("\"command\":\"TRANSLATE\"}\n");
|
||||
fflush(stdout);
|
||||
} else if (!strcmp(cmdLine, "TRANSLATE_DUMP\n")) {
|
||||
if (!DaemonJSON) {
|
||||
printf("NOTE JSONTRANSLATE\n");
|
||||
printf("NOTE TRANSLATE_DUMP\n");
|
||||
} else {
|
||||
printf("{");
|
||||
PrintJSONKeyPairString("response", "translate");
|
||||
PrintJSONKeyPairString("response", "translate_dump");
|
||||
printf("\"table\":");
|
||||
}
|
||||
DumpTranslationTable(stdout, 1);
|
||||
if (!DaemonJSON) {
|
||||
printf("\nNOTE ENDJSONTRANSLATE\n");
|
||||
printf("\nNOTE ENDTRANSLATE_DUMP\n");
|
||||
} else {
|
||||
printf(",\"command\":\"JSONTRANSLATE\"}\n");
|
||||
printf(",\"command\":\"TRANSLATE_DUMP\"}\n");
|
||||
}
|
||||
fflush(stdout);
|
||||
} else if (!strcmp(cmdLine, "REREAD\n")) {
|
||||
|
||||
Reference in New Issue
Block a user