def __init__(self, txt, locale, stripEndOfLine=True): if type(txt) == StringType: txt = unicode(txt) assert(type(txt) == UnicodeType) self.txt = txt.replace(u"\t", u" ").strip() #XXX The decision of whether to replace returns with spaces # is still up for debate. It helps the BreakIterator which # will otherwise assume sentences end at the '\n' even if # it really continues on the next line. # However, if the BreakIterator is not able to find sentences # with returns stripped the entire body of self.txt will be returned. if stripEndOfLine: self.txt = self.txt.replace(u"\r", u"").replace(u"\n", u" ") if type(locale) == UnicodeType: locale = str(locale) assert(type(locale) == StringType) #XXX This could be an invalid PyICU Locale. # The i18n.i18nmanager.isValidPyICULocale # could be used to check the value. pyLocale = Locale(locale) self.iterator = BreakIterator.createSentenceInstance(pyLocale) self.iterator.setText(self.txt)
def _init(self): if self._locale is not None: self._collator = Collator.createInstance(Locale(self._locale)) else: self._collator = Collator.createInstance() if self._strength is not None: self._collator.setStrength(self._strength)
def yieldFallbackLocales(self, localeSet): yielded = set() for locale in localeSet: if not locale in yielded: yielded.add(locale) yield locale localeObj = Locale(locale) country = localeObj.getCountry() language = localeObj.getLanguage() if language: l_plus_c = "%s_%s" % (language, country) if not l_plus_c in yielded: yielded.add(l_plus_c) yield l_plus_c if language and not language in yielded: yielded.add(language) yield language
def setPyICULocale(locale): """ Sets the c{PyICU.Locale} to the value passed in c{str} locale argument. If the locale passed in not a valid / supported PyICU locale a c{I18nException} is raised. @param locale: a c{str} locale @type locale: ASCII c{str} """ lc = Locale(locale) if not isValidPyICULocale(lc): raise I18nException, "Invalid PyICU Locale: '%s'" % locale Locale.setDefault(lc) # Store a reference to the PyICU Locale instance global _PYICU_LOCALE _PYICU_LOCALE = lc
def getLocaleName(self): if PYICU_INSTALLED: return Locale(self.LOCALE).getDisplayName() return self.LOCALE
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from createBase import LocalizationBase from poUtility import * from distutils.dir_util import copy_tree, remove_tree, mkpath from distutils.file_util import copy_file import os, sys import build_lib try: from PyICU import Locale # We want the English textual representation # of the locale to display to the user. Locale.setDefault(Locale("en")) PYICU_INSTALLED = True except: PYICU_INSTALLED = False if sys.platform == 'darwin': # This might be specific to Intel Mac "Leopard", but playing safe # See bug 11645. TIMEOUT = -1 else: TIMEOUT = 60 def ignore(output): pass
def compress(text): compressed = text cfunc = None for func in (_zlib, _bz2): c = func(text) if len(c) < len(compressed): compressed = c cfunc = func if cfunc: compress_counts[cfunc.__name__] += 1 else: compress_counts['none'] += 1 return compressed collator = Collator.createInstance(Locale('')) collator.setStrength(Collator.QUATERNARY) collation_key = collator.getCollationKey def make_output_file_name(input_file, options): """ Return output file name based on input file name. >>> from minimock import Mock >>> opts = Mock('options') >>> opts.output_file = 'abc' >>> make_output_file_name('123.tar.bz2', opts) 'abc' >>> opts.output_file = None