Creates a glossary with given name for the source and target languages, containing the entries in the given CSV data. The glossary may be used in the translate_text functions. The available glossary language pairs can be queried using get_glossary_languages(). Glossa
(
self,
name: str,
source_lang: str,
target_lang: str,
csv_data: Union[TextIO, BinaryIO, str, bytes, Any],
)
| 158 | return self._create_multilingual_glossary(name, glossary_dicts) |
| 159 | |
| 160 | def create_multilingual_glossary_from_csv( |
| 161 | self, |
| 162 | name: str, |
| 163 | source_lang: str, |
| 164 | target_lang: str, |
| 165 | csv_data: Union[TextIO, BinaryIO, str, bytes, Any], |
| 166 | ) -> MultilingualGlossaryInfo: |
| 167 | """Creates a glossary with given name for the source and target |
| 168 | languages, containing the entries in the given CSV data. |
| 169 | The glossary may be used in the translate_text functions. |
| 170 | |
| 171 | The available glossary language pairs can be queried using |
| 172 | get_glossary_languages(). Glossaries apply to languages, not specific |
| 173 | language variants. A glossary for a language applies to any variant |
| 174 | of that language: a glossary with target language EN may be used to |
| 175 | translate texts into both EN-US and EN-GB. |
| 176 | |
| 177 | This function allows you to upload a glossary CSV file that you have |
| 178 | downloaded from the DeepL website. |
| 179 | |
| 180 | Information about the expected CSV format can be found in the API |
| 181 | documentation: https://developers.deepl.com/docs/api-reference/glossaries#csv-comma-separated-values # noqa |
| 182 | |
| 183 | :param name: user-defined name to attach to glossary. |
| 184 | :param source_lang: Language of source entries. |
| 185 | :param target_lang: Language of target entries. |
| 186 | :param csv_data: CSV data containing glossary entries, either as a |
| 187 | file-like object or string or bytes containing file content. |
| 188 | :return: GlossaryInfo containing information about created glossary. |
| 189 | |
| 190 | :raises ValueError: If the glossary name is empty, or entries are |
| 191 | empty or invalid. |
| 192 | :raises DeepLException: If source and target language pair are not |
| 193 | supported for glossaries. |
| 194 | """ |
| 195 | entries = util.convert_csv_to_dict(csv_data) |
| 196 | |
| 197 | dictionaries = [ |
| 198 | MultilingualGlossaryDictionaryEntries( |
| 199 | source_lang, target_lang, entries |
| 200 | ) |
| 201 | ] |
| 202 | return self._create_multilingual_glossary(name, dictionaries) |
| 203 | |
| 204 | def _create_multilingual_glossary( |
| 205 | self, |