Beispiel #1
0
    def answers(self, language='en'):
        if self._answers.has_key(language):
            return self._answers[language]

        if language == '':
            language = 'en' # why not?
            
        answers = []
        for k in self._enums.keys():
            label = locale_dict_fetch_with_fallbacks(self._enums[k][0],
                                                     language)
            # is there a description for this enum?
            if self._enums[k][1] != {}: 
                # create a tuple with a localized description
                enum = ( label, k,
                         locale_dict_fetch_with_fallbacks(self._enums[k][1],
                                                         language) )
            else:
                enum = ( label, k, None)
                
            answers.append(enum)
            
        self._answers[language] = answers

        return answers
Beispiel #2
0
    def answers(self, language='en'):
        if self._answers.has_key(language):
            return self._answers[language]

        if language == '':
            language = 'en'  # why not?

        answers = []
        for k in self._enums.keys():
            label = locale_dict_fetch_with_fallbacks(self._enums[k][0],
                                                     language)
            # is there a description for this enum?
            if self._enums[k][1] != {}:
                # create a tuple with a localized description
                enum = (label, k,
                        locale_dict_fetch_with_fallbacks(
                            self._enums[k][1], language))
            else:
                enum = (label, k, None)

            answers.append(enum)

        self._answers[language] = answers

        return answers
Beispiel #3
0
def test_locale_dict_fetch_with_fallbacks():
    data_dict = {
        'de-ch': 'de-ch value',
        'de': 'de value',
        'en': 'en value',
        None: 'None value',
        'unused': 'we do not use this'
    }

    assert_equal(util.locale_dict_fetch_with_fallbacks(data_dict, 'de-ch'),
                 'de-ch value')
    data_dict.pop('de-ch')

    assert_equal(util.locale_dict_fetch_with_fallbacks(data_dict, 'de-ch'),
                 'de value')
    data_dict.pop('de')

    assert_equal(util.locale_dict_fetch_with_fallbacks(data_dict, 'de-ch'),
                 'en value')
    data_dict.pop('en')

    assert_equal(util.locale_dict_fetch_with_fallbacks(data_dict, 'de-ch'),
                 'None value')
Beispiel #4
0
 def description(self, language='en'):
     if language == '':
         language = 'en'  # why not?
     return locale_dict_fetch_with_fallbacks(self._descs, language)
Beispiel #5
0
 def label(self, language='en'):
     if language == '':
         language = 'en'  # why not?
     return locale_dict_fetch_with_fallbacks(self._labels, language)
Beispiel #6
0
 def description(self, language='en'):
     if language == '':
         language = 'en' # why not?
     return locale_dict_fetch_with_fallbacks(self._descs, language)
Beispiel #7
0
 def label(self, language='en'):
     if language == '':
         language = 'en' # why not?
     return locale_dict_fetch_with_fallbacks(self._labels, language)