Exemple #1
0
def test_turkish_upper_lower():
    AreEqual("ı".upper(),"I")
    AreEqual("İ".lower(),"i")

    # as defined in http://www.unicode.org/Public/UNIDATA/SpecialCasing.txt
    PERFECT_UNICODE_CASING=False
   
    import locale
    lang,encoding = locale.getlocale()

    if sys.platform == "win32":
        locale.setlocale(locale.LC_ALL, "turkish")
    else:
        locale.setlocale(locale.LC_ALL,"tr_TR")

    if PERFECT_UNICODE_CASING:
        AreEqual("I".lower(),"ı")
        AreEqual("i".upper(),"İ")
    else:
        # cpython compatibility
        AreEqual("I".lower(),"i")
        AreEqual("i".upper(),"I")

    locale.setlocale(locale.LC_ALL, (lang,encoding))

    # Note:
    # IronPython casing matches cpython implementation (linux and windows)
    # In order to take advantage of better build-in unicode support in Windows 
    # ToUpper/ToLower can be called directly
    if sys.platform == "cli":
        import System.Globalization.CultureInfo as CultureInfo
        AreEqual("I".ToLower(CultureInfo("tr-TR")),"ı")
        AreEqual("i".ToUpper(CultureInfo("tr-TR")),"İ")
Exemple #2
0
    def test_turkish_upper_lower(self):
        self.assertEqual(u"ı".upper(), u"I")
        self.assertEqual(u"İ".lower(), u"i" if is_cli else u"i̇")

        # as defined in http://www.unicode.org/Public/UNIDATA/SpecialCasing.txt
        PERFECT_UNICODE_CASING = False

        import locale
        lang, encoding = locale.getlocale(locale.LC_CTYPE)

        try:
            if is_cli or sys.version_info >= (3, 5):
                locale.setlocale(locale.LC_CTYPE, "tr_TR")
            else:
                locale.setlocale(locale.LC_CTYPE, "turkish")

            if PERFECT_UNICODE_CASING:
                self.assertEqual(u"I".lower(), u"ı")
                self.assertEqual(u"i".upper(), u"İ")
            else:
                # cpython compatibility
                self.assertEqual(u"I".lower(), u"i")
                self.assertEqual(u"i".upper(), u"I")

        finally:
            locale.setlocale(locale.LC_CTYPE, (lang, encoding))

        # Note:
        # IronPython casing matches cpython implementation (linux and windows)
        # In order to take advantage of better build-in unicode support in Windows
        # ToUpper/ToLower can be called directly
        if is_cli:
            import System.Globalization.CultureInfo as CultureInfo
            self.assertEqual(u"I".ToLower(CultureInfo("tr-TR")), u"ı")
            self.assertEqual(u"i".ToUpper(CultureInfo("tr-TR")), u"İ")
Exemple #3
0
 def get_voices(self, language=None):
     rv = []
     voices = []
     if language is not None:
         current_culture = CultureInfo.CurrentCulture
         if current_culture.IetfLanguageTag.startswith(language.lower()):
             voices.extend(self.GetInstalledVoices(current_culture))
         if language in locale_map:
             for locale in locale_map[language]:
                 culture = CultureInfo.GetCultureInfoByIetfLanguageTag(
                     f"{language}-{locale}")
                 voices.extend(self.GetInstalledVoices(culture))
         voices.extend(self.GetInstalledVoices(CultureInfo(language)))
     else:
         voices = self.GetInstalledVoices()
     if not voices:
         log.warning("No suitable TTS voice was found.")
         return rv
     for voice in voices:
         if not voice.Enabled:
             continue
         info = voice.VoiceInfo
         rv.append(
             VoiceInfo(
                 id=info.Id,
                 name=info.Name,
                 desc=info.Description,
                 language=info.Culture.IetfLanguageTag,
                 gender=info.Gender,
                 age=info.Age,
             ))
     return rv
Exemple #4
0
def is_rtl(lang):
    with suppress(ValueError):
        return CultureInfo(lang).TextInfo.IsRightToLeft