示例#1
0
    def test_locale_to_hyphen_dictionary(self):
        def t(x, expected=None):
            self.ae(dictionary_name_for_locale(x),
                    f'hyph_{expected}.dic' if expected else None)

        t('en', 'en_US')
        t('en_IN', 'en_GB')
        t('de', 'de_DE')
        t('es', 'es')
        t('nl', 'nl_NL')
        t('fr', 'fr')
        t('XXX')

        cache = [False]

        def cache_callback():
            cache[0] = True

        dp = path_to_dictionary(dictionary_name_for_locale('en'),
                                cache_callback)
        self.assertTrue(os.path.exists(dp),
                        f'The dictionary {dp} does not exist')
        self.assertTrue(cache[0])
        cache[0] = False
        self.assertTrue(
            os.path.exists(
                path_to_dictionary(dictionary_name_for_locale('es'),
                                   cache_callback)))
        self.assertFalse(cache[0])
示例#2
0
def dictionary_for_locale(locale):
    name = dictionary_name_for_locale(locale)
    if name is not None:
        from calibre_extensions import hyphen
        path = path_to_dictionary(name)
        fd = os.open(path, getattr(os, 'O_BINARY', 0) | os.O_RDONLY)
        return hyphen.load_dictionary(fd)
示例#3
0
def dictionary_for_locale(locale):
    global hyphen
    name = dictionary_name_for_locale(locale)
    if name is not None:
        path = path_to_dictionary(name)
        if hyphen is None:
            hyphen, hyphen_err = plugins['hyphen']
            if hyphen_err:
                raise RuntimeError(
                    'Failed to load the hyphen plugin with error: {}'.format(
                        hyphen_err))
        fd = os.open(path, getattr(os, 'O_BINARY', 0) | os.O_RDONLY)
        return hyphen.load_dictionary(fd)
示例#4
0
 def t(x, expected=None):
     self.ae(dictionary_name_for_locale(x),
             f'hyph_{expected}.dic' if expected else None)
示例#5
0
 def t(x, expected=None):
     self.ae(
         dictionary_name_for_locale(x),
         'hyph_{}.dic'.format(expected) if expected else None
     )