Пример #1
0
    def getAvailableLanguages(self, context):
        request = aq_get(context, 'REQUEST')
        default = self.getDefaultLang(context)
        portal_state = queryMultiAdapter((context, request),
                                         name=u'plone_portal_state')
        languages = portal_state.locale().displayNames.languages
        if self.haveLanguageFallback(context):
            default_marker = " (%s)" % translate(_(u"default language"),
                                                 context=request)
        else:
            default_marker = ""
        langs = [{
            'name':
            name,
            'title':
            translate(languages.get(name, title), context=request) +
            (name == default and default_marker or "")
        } for name, title in self._getTool(context).listSupportedLanguages()]

        def default_first(x, y):
            if x['name'] == default:
                return -1
            return 0

        langs.sort(default_first)
        return langs
Пример #2
0
 def getTranslation(self, string, source, dest, id=0):
     result = json.loads(self.getRawTranslation(string, source, dest).decode('utf-8'));
     result[u'responseData'][u'translatedText'] = decode_htmlentities(result[u'responseData'][u'translatedText'])
     self.request.response.setHeader("Content-type","application/json")
     return json.dumps({
         'id': id,
         'source': source,
         'dest': dest,
         'message': translate(_('message_translate', default=u'Are you sure you want to replace the current value for the language "{language}" by the generated translation "{translation}"?'), context=self.request),
         'result': result})
Пример #3
0
 def validate_required(self, instance, value, errors):
     res = super(MultilanguageFieldMixin, self).validate_required(instance, value, errors)
     if self.haveLanguageFallback(instance) and res:
         defaultLang = self.getDefaultLang(instance)
         if self._v_lang == defaultLang:
             request = aq_get(instance, 'REQUEST')
             label = self.widget.Label(instance)
             name = self.getName()
             if isinstance(label, Message):
                 label = translate(label, context=request)
             res = _(u'error_required_default',
                     default=u'${name} is required, please provide at least the default language.',
                     mapping={'name': label})
             res = translate(res, context=request)
             errors[name] = res
     return res
Пример #4
0
 def getAvailableLanguages(self, context):
     request = aq_get(context, 'REQUEST')
     default = self.getDefaultLang(context)
     portal_state = queryMultiAdapter((context, request), name=u'plone_portal_state')
     languages = portal_state.locale().displayNames.languages
     if self.haveLanguageFallback(context):
         default_marker = " (%s)" % translate(_(u"default language"), context=request)
     else:
         default_marker = ""
     langs = [{'name': name, 
               'title': translate(languages.get(name, title), context=request) +
                        (name == default and default_marker or "")} for name, title in self._getTool(context).listSupportedLanguages()]
     def default_first(x, y):
         if x['name'] == default:
             return -1
         return 0
     langs.sort(default_first)
     return langs
 def getTranslation(self, string, source, dest, id=0):
     result = json.loads(self.getRawTranslation(string, source, dest).decode("utf-8"))
     result[u"responseData"][u"translatedText"] = decode_htmlentities(result[u"responseData"][u"translatedText"])
     return json.dumps(
         {
             "id": id,
             "source": source,
             "dest": dest,
             "message": translate(
                 _(
                     "message_translate",
                     default=u'Are you sure you want to replace the current value for the language "{language}" by the generated translation "{translation}"?',
                 ),
                 context=self.request,
             ),
             "result": result,
         }
     )
Пример #6
0
 def validate_required(self, instance, value, errors):
     res = super(MultilanguageFieldMixin,
                 self).validate_required(instance, value, errors)
     if self.haveLanguageFallback(instance) and res:
         defaultLang = self.getDefaultLang(instance)
         if self._v_lang == defaultLang:
             request = aq_get(instance, 'REQUEST')
             label = self.widget.Label(instance)
             name = self.getName()
             if isinstance(label, Message):
                 label = translate(label, context=request)
             res = _(
                 u'error_required_default',
                 default=
                 u'${name} is required, please provide at least the default language.',
                 mapping={'name': label})
             res = translate(res, context=request)
             errors[name] = res
     return res
 def getTranslation(self, string, source, dest, id=0):
     result = json.loads(
         self.getRawTranslation(string, source, dest).decode('utf-8'))
     result[u'responseData'][u'translatedText'] = decode_htmlentities(
         result[u'responseData'][u'translatedText'])
     self.request.response.setHeader("Content-type", "application/json")
     return json.dumps({
         'id':
         id,
         'source':
         source,
         'dest':
         dest,
         'message':
         translate(_(
             'message_translate',
             default=
             u'Are you sure you want to replace the current value for the language "{language}" by the generated translation "{translation}"?'
         ),
                   context=self.request),
         'result':
         result
     })