mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-11 04:17:58 +00:00
Add BCP47 unicode tags for Locale enum
Co-authored-by: Danny <1695103+Rapptz@users.noreply.github.com>
This commit is contained in:
parent
774b934f74
commit
2502a783cb
@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import types
|
||||
@ -694,6 +695,42 @@ class MFALevel(Enum, comparable=True):
|
||||
require_2fa = 1
|
||||
|
||||
|
||||
_UNICODE_LANG_MAP: Dict[str, str] = {
|
||||
'bg': 'bg-BG',
|
||||
'zh-CN': 'zh-CN',
|
||||
'zh-TW': 'zh-TW',
|
||||
'hr': 'hr-HR',
|
||||
'cs': 'cs-CZ',
|
||||
'da': 'da-DK',
|
||||
'nl': 'nl-NL',
|
||||
'en-US': 'en-US',
|
||||
'en-GB': 'en-GB',
|
||||
'fi': 'fi-FI',
|
||||
'fr': 'fr-FR',
|
||||
'de': 'de-DE',
|
||||
'el': 'el-GR',
|
||||
'hi': 'hi-IN',
|
||||
'hu': 'hu-HU',
|
||||
'id': 'id-ID',
|
||||
'it': 'it-IT',
|
||||
'ja': 'ja-JP',
|
||||
'ko': 'ko-KR',
|
||||
'lt': 'lt-LT',
|
||||
'no': 'no-NO',
|
||||
'pl': 'pl-PL',
|
||||
'pt-BR': 'pt-BR',
|
||||
'ro': 'ro-RO',
|
||||
'ru': 'ru-RU',
|
||||
'es-ES': 'es-ES',
|
||||
'es-419': 'es-419',
|
||||
'sv-SE': 'sv-SE',
|
||||
'th': 'th-TH',
|
||||
'tr': 'tr-TR',
|
||||
'uk': 'uk-UA',
|
||||
'vi': 'vi-VN',
|
||||
}
|
||||
|
||||
|
||||
class Locale(Enum):
|
||||
american_english = 'en-US'
|
||||
british_english = 'en-GB'
|
||||
@ -731,6 +768,17 @@ class Locale(Enum):
|
||||
def __str__(self) -> str:
|
||||
return self.value
|
||||
|
||||
@property
|
||||
def language_code(self) -> str:
|
||||
""":class:`str`: Returns the locale's BCP 47 language code in the format of ``language-COUNTRY``.
|
||||
|
||||
This is derived from a predefined mapping based on Discord's supported locales.
|
||||
If no mapping exists for the current locale, this returns the raw locale value as a fallback.
|
||||
|
||||
.. versionadded:: 2.6
|
||||
"""
|
||||
return _UNICODE_LANG_MAP.get(self.value, self.value)
|
||||
|
||||
|
||||
E = TypeVar('E', bound='Enum')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user