Locales
Locale
Singleton class for managing supported languages and ISO language codes.
Provides functionality to handle language codes in both ISO 639-1 (two-letter) and full name formats.
Attributes:
Name | Type | Description |
---|---|---|
_instance |
Locale or None
|
Singleton instance of the class |
_supported_languages |
set
|
Set of supported ISO 639-1 language codes |
Methods:
Name | Description |
---|---|
get_supported_languages |
Returns set of supported languages in specified format |
is_language_supported |
Checks if a language is supported |
get_pt1_from_full |
Converts full language name to ISO 639-1 code |
get_full_from_pt1 |
Converts ISO 639-1 code to full language name |
Source code in apps/annotator/code/text_processor/locales.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 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 |
|
__new__()
Creates or returns the singleton instance of Locale.
Returns:
Type | Description |
---|---|
Locale
|
The singleton instance |
Source code in apps/annotator/code/text_processor/locales.py
35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
get_full_from_pt1(language, lower=True)
staticmethod
Converts ISO 639-1 code to full language name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
language
|
str
|
ISO 639-1 two-letter language code |
required |
lower
|
bool
|
If True, returns lowercase name |
True
|
Returns:
Type | Description |
---|---|
str
|
Full language name |
Source code in apps/annotator/code/text_processor/locales.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
get_pt1_from_full(language)
staticmethod
Converts full language name to ISO 639-1 code.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
language
|
str
|
Full language name |
required |
Returns:
Type | Description |
---|---|
str
|
ISO 639-1 two-letter language code |
Source code in apps/annotator/code/text_processor/locales.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
get_supported_languages(kind=FORMAT_PT1)
Returns set of supported languages in specified format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kind
|
int
|
Format type for returned language codes: - FORMAT_PT1: ISO 639-1 two-letter codes - FORMAT_FULL: Full language names |
FORMAT_PT1
|
Returns:
Type | Description |
---|---|
set
|
Set of language codes or names |
Raises:
Type | Description |
---|---|
Exception
|
If kind parameter is not implemented |
Source code in apps/annotator/code/text_processor/locales.py
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 |
|
is_language_supported(language)
Checks if a language is in the supported languages set.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
language
|
str
|
Language code or name to check |
required |
Returns:
Type | Description |
---|---|
bool
|
True if language is supported, False otherwise |
Source code in apps/annotator/code/text_processor/locales.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|