File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 2121FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2222DEALINGS IN THE SOFTWARE.
2323"""
24+
2425from __future__ import annotations
2526
2627import types
@@ -694,6 +695,42 @@ class MFALevel(Enum, comparable=True):
694695 require_2fa = 1
695696
696697
698+ _UNICODE_LANG_MAP : Dict [str , str ] = {
699+ 'bg' : 'bg-BG' ,
700+ 'zh-CN' : 'zh-CN' ,
701+ 'zh-TW' : 'zh-TW' ,
702+ 'hr' : 'hr-HR' ,
703+ 'cs' : 'cs-CZ' ,
704+ 'da' : 'da-DK' ,
705+ 'nl' : 'nl-NL' ,
706+ 'en-US' : 'en-US' ,
707+ 'en-GB' : 'en-GB' ,
708+ 'fi' : 'fi-FI' ,
709+ 'fr' : 'fr-FR' ,
710+ 'de' : 'de-DE' ,
711+ 'el' : 'el-GR' ,
712+ 'hi' : 'hi-IN' ,
713+ 'hu' : 'hu-HU' ,
714+ 'id' : 'id-ID' ,
715+ 'it' : 'it-IT' ,
716+ 'ja' : 'ja-JP' ,
717+ 'ko' : 'ko-KR' ,
718+ 'lt' : 'lt-LT' ,
719+ 'no' : 'no-NO' ,
720+ 'pl' : 'pl-PL' ,
721+ 'pt-BR' : 'pt-BR' ,
722+ 'ro' : 'ro-RO' ,
723+ 'ru' : 'ru-RU' ,
724+ 'es-ES' : 'es-ES' ,
725+ 'es-419' : 'es-419' ,
726+ 'sv-SE' : 'sv-SE' ,
727+ 'th' : 'th-TH' ,
728+ 'tr' : 'tr-TR' ,
729+ 'uk' : 'uk-UA' ,
730+ 'vi' : 'vi-VN' ,
731+ }
732+
733+
697734class Locale (Enum ):
698735 american_english = 'en-US'
699736 british_english = 'en-GB'
@@ -731,6 +768,17 @@ class Locale(Enum):
731768 def __str__ (self ) -> str :
732769 return self .value
733770
771+ @property
772+ def language_code (self ) -> str :
773+ """:class:`str`: Returns the locale's BCP 47 language code in the format of ``language-COUNTRY``.
774+
775+ This is derived from a predefined mapping based on Discord's supported locales.
776+ If no mapping exists for the current locale, this returns the raw locale value as a fallback.
777+
778+ .. versionadded:: 2.6
779+ """
780+ return _UNICODE_LANG_MAP .get (self .value , self .value )
781+
734782
735783E = TypeVar ('E' , bound = 'Enum' )
736784
You can’t perform that action at this time.
0 commit comments