As can be seen from
LanguageData["Properties"] // Multicolumn
Mathematica's translation capabilities seem to be very limited. It can translate month names, colors and numbers, but, apparently, not arbitrary words.
Grid[ LanguageData[ { Entity["Language", "English"], Entity["Language", "German"], Entity["Language", "Spanish"] }, "NumeralWords"], Frame -> All, Alignment -> Left]
To translate arbitrary words one probably has to use WolframAlpha
:
word = "femme";trans = WolframAlpha[word <> " from french to german", "PodCells"]
This doesn' t look too bad, but how do we get "femme", "Frau" and "Ehefrau" as a List
of String
s ? Executing
trans // FullForm
we see a complex structure of RowBoxes
- instructions. To eliminate the unwanted elements I have written
res = DeleteCases[ Cases[trans, _String, Infinity],"\")\"" | "\"(\"" | "\" \"" | "\" | \"" | "Columns" | "\"French\"" | "\"from\"" | "\"general\"" |"\"German\"" | "Output" | "\"person\"" | "Rows" | "RowDefault" | "RowsIndexed" | "Times" |"\"to\"" | "\"translate\"" | "\[NoBreak]" | "Verdana", Infinity] // DeleteDuplicates
{"\"femme\"", "\"Frau\"", "\"Ehefrau\"", "\"wife\"", "\"woman\""}
To eliminate the backslash characters:
str = ToCharacterCode[res] /. (34) -> Sequence[] // FromCharacterCode
{"femme", "Frau", "Ehefrau", "wife", "woman"}
Since we want to translate from french to german we finally eliminate the englisch words :
Flatten @ Map[Intersection[DictionaryLookup[{#, All}], str] &,{"French", "German"}]
{"femme", "Ehefrau", "Frau"}
Voilà, a femme is a wife is a Frau - but at what expense !
How can I simplify this code (especially the RowBoxes
- destruction) ?
Are there alternate ways to translate simple words from one language to another ?