Documentation for loaders
module
This module defines the PyI18n loaders which load translations from files in YAML or JSON format.
LoaderType
Enum for the different loader types.
Source code in pyi18n/loaders.py
14 15 16 17 18 |
|
PyI18nBaseLoader
PyI18n Base Loader class, supports yaml and json
Attributes:
Name | Type | Description |
---|---|---|
load_path |
str
|
path to translations |
namespaced |
bool
|
tells loader should look for namespaces |
_type |
str
|
loader type |
Source code in pyi18n/loaders.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
__init__(load_path='locales/', namespaced=False)
Initialize loader class
Parameters:
Name | Type | Description | Default |
---|---|---|---|
load_path |
str
|
path to translations |
'locales/'
|
namespaced |
bool
|
namespaces support |
False
|
Return
None
Source code in pyi18n/loaders.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
__load_file(file_path, ext, ser_mod, locale)
loads content, should not be called directly
Return
dict: loaded content
Source code in pyi18n/loaders.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
get_path()
Return loader path
Return
str: loader path
Source code in pyi18n/loaders.py
135 136 137 138 139 140 141 |
|
load(locales, ser_mod)
Load translations for given locales, should be overridden in child classes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
locales |
tuple
|
locales to load |
required |
Return
dict: loaded translations
Notes
Custom load function should be implemented in child classes and return python dict
Source code in pyi18n/loaders.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
type()
Return loader type
Return
str: loader type
Source code in pyi18n/loaders.py
127 128 129 130 131 132 133 |
|
PyI18nJsonLoader
Bases: PyI18nBaseLoader
PyI18n JSON Loader class
Attributes:
Name | Type | Description |
---|---|---|
load_path |
str
|
path to translations |
namespaced |
bool
|
tells loader should look for namespaces |
_type |
str
|
loader type |
Source code in pyi18n/loaders.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
load(locales)
Load translations for given locales using json
Inherits from PyI18nBaseLoader
Parameters:
Name | Type | Description | Default |
---|---|---|---|
locales |
tuple
|
locales to load |
required |
Return
dict: loaded translations
Source code in pyi18n/loaders.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
PyI18nYamlLoader
Bases: PyI18nBaseLoader
PyI18n YAML Loader class
Attributes:
Name | Type | Description |
---|---|---|
load_path |
str
|
path to translations |
namespaced |
bool
|
tells loader should look for namespaces |
_type |
str
|
loader type |
Source code in pyi18n/loaders.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
load(locales)
Load translations for given locales using yaml
Inherits from PyI18nBaseLoader
Parameters:
Name | Type | Description | Default |
---|---|---|---|
locales |
tuple
|
locales to load |
required |
Return
dict: loaded translations
Source code in pyi18n/loaders.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|