Package: word-translator-py
word-translator-pyA word translator usingWordReferenceto retrieve all the information contained in the HTML
document and return the data (encoded or decoded) as object, dict or json.Installation$pipinstallword-translator-pyUsageTranslate a wordas in the following example:fromword_translator_clientimport*translation:Translation=retrieve_translation(from_lang='es',to_lang='en',word='casa')print(translation.to_json_encoded())This is a fragment of the output:{"from_lang": "es","to_lang": "en","from_word": "casa","entry_sections": [{"section_type": "principal_translations","entry_words": [{"from_word": {"from_word": "casa","from_grammar": "nf"},"tone": "","context": "edificio, vivienda","to_words": [{"to_word": "house","to_grammar": "n","note": ""},{"to_word": "place","to_grammar": "n","note": "informal"}],"from_examples": ["Todas las casas de este barrio se construyeron según los mismos planos.","Vive en una casa de una sola planta con jardín y piscina."],"to_examples": ["He lives in a one-story house with a garden and a pool."]},...Thesection_typeattribute can be: principal_translations or additional_translations or compound_forms or
phrasal_verbs. The other values are as shown on the wordreference website.The Translation class structureTranslation├ from_lang├ to_lang├ from_word└ entry_sections []├ section_type└ entry_words []├ from_word├ from_word└ from_grammar├ tone├ context├ to_words []├ to_word├ to_grammar└ note├ from_examples []└ to_examples []All identified elementsAll usagesRetrievingYou can retrieve a wordreference translation object this way:fromword_translator_clientimport*translation:Translation=retrieve_translation(from_lang='es',to_lang='en',word='casa')Encoded vs decodedRememberjardínisencodedandjard\u00ednisdecoded. The software point of view is applied. Thus, prefer
the encoded way when displaying data to users (as in the wordreference website).All the ways of using a translationThe defaultobjectisencoded, so in the example above the next sentence:translation.entry_sections[0].entry_words[0].from_examples[1]will give you the following text:Vive en una casa de una sola planta con jardín y piscina.See example_1_for_encoded_object().Decoded object, the next sentence:to_decoded_translation(translation).entry_sections[0].entry_words[0].from_examples[1]will give you the following text:Vive en una casa de una sola planta con jard\u00edn y piscina.See example_2_for_decoded_object().Encoded dict, the next sentence:translation.to_dict_encoded()['entry_sections'][0]['entry_words'][0]['from_examples'][1]will give you the following text:Vive en una casa de una sola planta con jardín y piscina.See example_3_for_encoded_dict().Decoded dict, the next sentence:translation.to_dict_decoded()['entry_sections'][0]['entry_words'][0]['from_examples'][1]will give you the following text:Vive en una casa de una sola planta con jard\u00edn y piscina.See example_4_for_decoded_dict().Encoded json, the next sentence:translation.to_json_encoded()will give you a text containing the following fragment:"Vive en una casa de una sola planta con jardín y piscina."See example_5_for_encoded_json().Decoded json, the next sentence:translation.to_json_decoded()will give you a text containing the following fragment:"Vive en una casa de una sola planta con jard\u00edn y piscina."See example_6_for_decoded_json().Console table, the next snippet:fromword_translator_clientimport*fromtranslation_as_console_tableimportretrieve_console_tabletranslation:Translation=retrieve_translation(from_lang='es',to_lang='en',word='casa')console_table:str=retrieve_console_table(translation)will give you a text with a formatted table like this:The spatial distribution is as shown on the wordreference website.
See example_7_for_console_table() from module translation_as_console_table.DisclaimerThis package was created by reading the HTML documents fromwordreference.com.
As wordreference could change the output, if you find some error please email us atsoftwarelma@gmail.comor email the author (Guillermo Rodolfo Ellison) atguillermoellison@gmail.com.