Shorcut method to retrieve translations for a given object.
322958
def get_translations(self, obj, language=None):
        
        lookup = {"identifier": obj.linguist_identifier, "object_id": obj.pk}

        if language is not None:
            lookup["language"] = language

        return self.get_queryset().filter(**lookup)
467449
def get_translations(self):
        
        ctx = _request_ctx_stack.top
        if ctx is None:
            return NullTranslations()

        locale = get_locale()

        cache = self.get_translations_cache(ctx)

        translations = cache.get(str(locale))

        if translations is None:
            translations = self._get_translation_for_locale(locale)
            cache[str(locale)] = translations

        return translations
346428
private String translate(final Object messageObject) {
		if (messageObject instanceof Message) {
			Message message = (Message) messageObject;
			return I18nUtilities.format(locale, message.getMessage(), (Object[]) message.getArgs());
		} else if (messageObject != null) {
			return I18nUtilities.format(locale, messageObject.toString());
		}

		return null;
	}
512579
def translate(self):
        """"""
        varnames = set()
        ident = self.ident
        funcnames = set([ident])

        arg_exprs = []
        for arg in self.args:
            subexprs, subvars, subfuncs = arg.translate()
            varnames.update(subvars)
            funcnames.update(subfuncs)

            # Create a subexpression that joins the result components of
            # the arguments.
            arg_exprs.append(ex_call(
                ast.Attribute(ex_literal(u''), 'join', ast.Load()),
                [ex_call(
                    'map',
                    [
                        ex_rvalue(str.__name__),
                        ast.List(subexprs, ast.Load()),
                    ]
                )],
            ))

        subexpr_call = ex_call(
            FUNCTION_PREFIX + ident,
            arg_exprs
        )
        return [subexpr_call], varnames, funcnames
1064379
def translator(self):
        """"""
        if self._translator is None:
            languages = self.lang
            if not languages:
                return gettext.NullTranslations()
            if not isinstance(languages, list):
                languages = [languages]
            translator = gettext.NullTranslations()
            for name, i18n_dir in [
                    (
                        'biryani',
                        os.path.join(pkg_resources.get_distribution('biryani').location, 'biryani', 'i18n'),
                        ),
                    (
                        conf['country_package'].replace('_', '-'),
                        os.path.join(pkg_resources.get_distribution(conf['country_package']).location,
                            conf['country_package'], 'i18n'),
                        ),
                    ]:
                if i18n_dir is not None:
                    translator = new_translator(name, i18n_dir, languages, fallback = translator)
            translator = new_translator(conf['package_name'], conf['i18n_dir'], languages, fallback = translator)
            self._translator = translator
        return self._translator
797385
def get_obj(source, extract=None, child_transform=None, transform=None):
  """"""
  if extract is None:
    obj = source
  else:
    obj = extract(source)

  if child_transform is None:
    data = obj
  else:
    data = dict()
    for k, v in child_transform.items():
      try:
        data[k] = v(obj)
      except Exception as ex:
        raise Exception("An error occurred with child {0}".format(k)) from ex

  if transform is None:
    return data
  else:
    return transform(data)
941335
function fetchAttributeTranslations( $asObject = true )
    {
        return eZPersistentObject::fetchObjectList( eZContentObjectAttribute::definition(),
                                                    null,
                                                    array( "contentclassattribute_id" => $this->ContentClassAttributeID,
                                                           "contentobject_id" => $this->ContentObjectID,
                                                           "version" => $this->Version ),
                                                    null,
                                                    null,
                                                    $asObject);
    }
876567
def collect_translations(self):
        """"""
        languages = {}
        locale_data = {}

        for language_code, label in settings.LANGUAGES:
            languages[language_code] = '%s' % label

            # Create django translation engine for `language_code`
            trans_cat, trans_fallback_cat = self.get_catalog(language_code)

            # Add the meta object
            locale_data[language_code] = {}
            locale_data[language_code][""] = self.make_header(language_code, trans_cat)
            num_plurals = self._num_plurals(trans_cat)

            # Next code is largely taken from Django@master (01.10.2017) from `django.views.i18n JavaScriptCatalogue`
            pdict = {}
            seen_keys = set()

            for key, value in itertools.chain(six.iteritems(trans_cat), six.iteritems(trans_fallback_cat)):
                if key == '' or key in seen_keys:
                    continue

                if isinstance(key, six.string_types):
                    locale_data[language_code][key] = [value]

                elif isinstance(key, tuple):
                    msgid, cnt = key
                    pdict.setdefault(msgid, {})[cnt] = value

                else:
                    raise TypeError(key)
                seen_keys.add(key)

            for k, v in pdict.items():
                locale_data[language_code][k] = [v.get(i, '') for i in range(num_plurals)]

        for key, value in locale_data.items():
            locale_data[key] = json.dumps(value)

        return languages, locale_data
336556
def translate(self, mo):
        """"""
        attrs = {}
        groupdict = mo.groupdict()
        for name, value in compat_iteritems(groupdict):
            if value is None:
                value = None
            elif self._int_re.match(value):
                value = int(value)
            elif self._float_re.match(value):
                value = float(value)
            attrs[name] = (value)
        return Struct(attrs)
944349
def translation(first, second):
    """"""
    if len(first) != len(second):
        raise WrongLengthException('The lists are not of the same length!')
    return dict(zip(first, second))
42698
def _decrypt_object(obj, translate_newlines=False):
    '''
    
    '''
    if salt.utils.stringio.is_readable(obj):
        return _decrypt_object(obj.getvalue(), translate_newlines)
    if isinstance(obj, six.string_types):
        try:
            return _decrypt_ciphertext(obj,
                                       translate_newlines=translate_newlines)
        except (fernet.InvalidToken, TypeError):
            return obj

    elif isinstance(obj, dict):
        for key, value in six.iteritems(obj):
            obj[key] = _decrypt_object(value,
                                       translate_newlines=translate_newlines)
        return obj
    elif isinstance(obj, list):
        for key, value in enumerate(obj):
            obj[key] = _decrypt_object(value,
                                       translate_newlines=translate_newlines)
        return obj
    else:
        return obj
62986
def get_language_from_json(language, key):
    """"""

    file_name = os.path.join(
        os.path.dirname(__file__),
        'languages',
        '{0}.json').format(key.lower())

    if os.path.exists(file_name):
        try:
            with open(file_name, 'r', encoding='utf-8') as fh:
                languages = json.loads(fh.read())
                if languages.get(language.lower()):
                    return languages[language.lower()]
        except:
            log.traceback(logging.DEBUG)

    return None
1029290
def get_for_model(self, obj):
        """"""
        qs = Tag.objects.language(get_language())
        qs = qs.filter(
            tagged_items__content_type=ctype_models.ContentType.objects.get_for_model(obj))  # NOQA
        return qs.distinct()
106001
def get_value(self, context, obj, field_name):
        
        try:
            language = get_language()
            value = self.get_translated_value(obj, field_name, language)
            if value:
                return value
            if self.FALLBACK:
                for lang, lang_name in settings.LANGUAGES:
                    if lang == language:
                        # already tried this one...
                        continue
                    value = self.get_translated_value(obj, field_name, lang)
                    if value:
                        return value
            untranslated = getattr(obj, field_name)
            if self._is_truthy(untranslated):
                return untranslated
            else:
                return self.EMPTY_VALUE
        except Exception:
            if settings.TEMPLATE_DEBUG:
                raise
            return self.EMPTY_VALUE
400753
function translateResponse(obj){
  for(var k in obj){
    if(obj[k] instanceof Array){
      for(var i=0;i<obj[k].length;i++){
        // just an array of strings
        if(obj[k][i] instanceof Buffer){
          obj[k][i] = obj[k][i].toString()
        } else {
          // and array of objects..
           for(var k1 in obj[k][i]){
            if(obj[k][i][k1] instanceof Buffer){
              obj[k][i][k1] = obj[k][i][k1].toString()
            }
           }
        }
      }
    } else if(obj[k] instanceof Buffer) {
      obj[k] = obj[k].toString()
    } else {
      for(var rk in obj[k]){
        if(obj[k][rk] instanceof Buffer){
          obj[k][rk] = obj[k][rk].toString()
        } else if(obj[k][rk] instanceof Array){
          for(var i=0;i<obj[k][rk].length;i++){
             if(obj[k][rk][i] instanceof Buffer){
               obj[k][rk][i] = obj[k][rk][i].toString()
             } else {
              obj[k][rk][i] = obj[k][rk][i];
             }
          }
        } 
      }
    }
  }
  return obj
}
373251
def get_elements(self, object_list):
        
        result = []
        for item in object_list:
            if isinstance(item, list):
                result += self.get_elements(item)
            elif isinstance(item, TranslatableModel):
                result.append(item)
        return result
394247
def translate_dict(cls, val):
        """"""
        escaped = ', '.join(
            ["{} -> {}".format(cls.translate_str(k), cls.translate(v)) for k, v in val.items()]
        )
        return 'Map({})'.format(escaped)