Creates a glossary with given name for the source and target languages, containing the entries in dictionary. The glossary may be used in the translate_text functions. Only certain language pairs are supported. The available language pairs can be queried using get_gl
(
self,
name: str,
source_lang: Union[str, Language],
target_lang: Union[str, Language],
entries: Dict[str, str],
)
| 1040 | return Usage(json) |
| 1041 | |
| 1042 | def create_glossary( |
| 1043 | self, |
| 1044 | name: str, |
| 1045 | source_lang: Union[str, Language], |
| 1046 | target_lang: Union[str, Language], |
| 1047 | entries: Dict[str, str], |
| 1048 | ) -> GlossaryInfo: |
| 1049 | """Creates a glossary with given name for the source and target |
| 1050 | languages, containing the entries in dictionary. The glossary may be |
| 1051 | used in the translate_text functions. |
| 1052 | |
| 1053 | Only certain language pairs are supported. The available language pairs |
| 1054 | can be queried using get_glossary_languages(). Glossaries are not |
| 1055 | regional specific: a glossary with target language EN may be used to |
| 1056 | translate texts into both EN-US and EN-GB. |
| 1057 | |
| 1058 | This function requires the glossary entries to be provided as a |
| 1059 | dictionary of source-target terms. To create a glossary from a CSV file |
| 1060 | downloaded from the DeepL website, see create_glossary_from_csv(). |
| 1061 | |
| 1062 | :param name: user-defined name to attach to glossary. |
| 1063 | :param source_lang: Language of source terms. |
| 1064 | :param target_lang: Language of target terms. |
| 1065 | :param entries: dictionary of terms to insert in glossary, with the |
| 1066 | keys and values representing source and target terms respectively. |
| 1067 | :return: GlossaryInfo containing information about created glossary. |
| 1068 | |
| 1069 | :raises ValueError: If the glossary name is empty, or entries are |
| 1070 | empty or invalid. |
| 1071 | :raises DeepLException: If source and target language pair are not |
| 1072 | supported for glossaries. |
| 1073 | """ |
| 1074 | if not entries: |
| 1075 | raise ValueError("glossary entries must not be empty") |
| 1076 | |
| 1077 | return self._create_glossary( |
| 1078 | name, |
| 1079 | source_lang, |
| 1080 | target_lang, |
| 1081 | "tsv", |
| 1082 | util.convert_dict_to_tsv(entries), |
| 1083 | ) |
| 1084 | |
| 1085 | def create_glossary_from_csv( |
| 1086 | self, |