|
| 1 | +## LoadMode |
| 2 | + |
| 3 | +An enumeration representing two loading modes. |
| 4 | + |
| 5 | +| **Enum** | Description | |
| 6 | +| -------- | ------------------------------------------------------------ | |
| 7 | +| REALTIME | Static data files are read for each conversion. | |
| 8 | +| ONETIME | Static data files are only read once when the object is instantiated for the first time. | |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +## Lang |
| 13 | + |
| 14 | +A working class for language conversion. |
| 15 | + |
| 16 | +### Constructor |
| 17 | + |
| 18 | +```python |
| 19 | +Lang(include, load_mode) |
| 20 | +``` |
| 21 | + |
| 22 | +| Parameter | Type | Default | Description | |
| 23 | +| --------- | -------- | ----------------- | ------------------------------------------------------------ | |
| 24 | +| include | tuple | () | A tuple of expressions which are importing language dictionaries.<br>There are two forms of this expression, for example: <br>1. full: `"./en_us.lang as en_us"`<br>2. short: `"./en_us.lang"`<br>Note that when using the short form, the name of the associated language will be the name of the file. | |
| 25 | +| load_mode | LoadMode | LoadMode.REALTIME | The option for loading mode. | |
| 26 | + |
| 27 | +> The detail of the data format supported by imported language dictionaries is in [doc](https://github.com/leoweyr/Python-OOPMultilang/blob/main/doc/data%20standard.md#supportdataformat). |
| 28 | +
|
| 29 | +### Default setting |
| 30 | + |
| 31 | +``` |
| 32 | +Lang().default_lang(source_lang, target_lang) |
| 33 | +``` |
| 34 | + |
| 35 | +| Parameter | Type | Default | Description | |
| 36 | +| ----------- | ------ | ------- | ----------------------------------------------------------- | |
| 37 | +| source_lang | string | "" | The option for the default source language to convert from. | |
| 38 | +| target_lang | string | "" | The option for the default target language to convert to. | |
| 39 | + |
| 40 | +> `None` represents it is the universal word, not a specific language. |
| 41 | +
|
| 42 | +### Conversion |
| 43 | + |
| 44 | +> The description of the universal word and the native word is in [doc](https://github.com/leoweyr/Python-OOPMultilang/blob/main/doc/data%20standard.md). |
| 45 | +
|
| 46 | +#### Lang().str(word, source_lang, target_lang) |
| 47 | + |
| 48 | +String conversion method. |
| 49 | + |
| 50 | +| Parameter | Type | Default | Description | |
| 51 | +| ----------- | ------ | ------- | ------------------------------------ | |
| 52 | +| word | string | | A word to be converted. | |
| 53 | +| source_lang | string | "" | The source language to convert from. | |
| 54 | +| target_lang | string | "" | The target language to convert to. | |
| 55 | + |
| 56 | +> `""` represents it is the default language set in `Lang().default_lang()`. |
| 57 | +
|
| 58 | +#### Lang().universal |
| 59 | + |
| 60 | +Object-oriented paradigm conversion method, only supports converting a universal word into other native word. |
| 61 | + |
| 62 | +There are two syntax statements: |
| 63 | + |
| 64 | +```python |
| 65 | +# Pure object-oriented paradigm suffix. |
| 66 | +Lang().universal.* |
| 67 | + |
| 68 | +# End of suffix with the target language to convert to. |
| 69 | +Lang().universal.*.target_lang |
| 70 | + |
| 71 | +# `*` represents a specific universal word. |
| 72 | +``` |
| 73 | + |
| 74 | +> For the difference between two methods in practical application, please see [example](https://github.com/leoweyr/Python-OOPMultilang/tree/main/examples). |
| 75 | +
|
| 76 | + |
| 77 | + |
| 78 | +## LangDictSearchError |
| 79 | + |
| 80 | +An exception class thrown when language conversion error occurs. |
| 81 | + |
| 82 | +### Attributes |
| 83 | + |
| 84 | +<table> |
| 85 | + <tr> |
| 86 | + <td><code>LangDictSearchError().type</code></td> |
| 87 | + <td>Return the type of error reason.</br>● LangDictSearchError.UNIVERSAL_WORD_EXIST_ERROR</br>● LangDictSearchError.SOURCE_LANG_DICT_MATCH_ERROR</br>● LangDictSearchError.TARGET_LANG_DICT_MATCH_ERROR</td> |
| 88 | + </tr> |
| 89 | + <tr> |
| 90 | + <td><code>LangDictSearchError().word</code></td> |
| 91 | + <td>Return the word being converted that caused the error to occur.</td> |
| 92 | + </tr> |
| 93 | + <tr> |
| 94 | + <td><code>LangDictSearchError().position</code></td> |
| 95 | + <td>Return the name of language associated with language dictionary which caused the error to occur.</td> |
| 96 | + </tr> |
| 97 | +</table> |
0 commit comments