https://developer.zendesk.com/rest_api/docs/help_center/translations#list-translations
553824
def help_center_category_translations(self, category_id, **kwargs):
        ""
        api_path = "/api/v2/help_center/categories/{category_id}/translations.json"
        api_path = api_path.format(category_id=category_id)
        return self.call(api_path, **kwargs)
94108
def _get_translate():
    
    translate = {}
    model_path = pkg_resources.resource_filename('hwrt', 'misc/')
    translation_csv = os.path.join(model_path, 'latex2writemathindex.csv')
    arguments = {'newline': '', 'encoding': 'utf8'}
    with open(translation_csv, 'rt', **arguments) as csvfile:
        contents = csvfile.read()
    lines = contents.split("\n")
    for csvrow in lines:
        csvrow = csvrow.split(',')
        if len(csvrow) == 1:
            writemathid = csvrow[0]
            latex = ""
        else:
            writemathid, latex = csvrow[0], csvrow[1:]
            latex = ','.join(latex)
        translate[latex] = writemathid
    return translate
599599
def get_translations(self, context_id):
        
        _mask = ('[mask[addressTranslations[customerIpAddressRecord,'
                 'internalIpAddressRecord]]]')
        context = self.get_tunnel_context(context_id, mask=_mask)
        # Pull the internal and remote IP addresses into the translation
        for translation in context.get('addressTranslations', []):
            remote_ip = translation.get('customerIpAddressRecord', {})
            internal_ip = translation.get('internalIpAddressRecord', {})
            translation['customerIpAddress'] = remote_ip.get('ipAddress', '')
            translation['internalIpAddress'] = internal_ip.get('ipAddress', '')
            translation.pop('customerIpAddressRecord', None)
            translation.pop('internalIpAddressRecord', None)
        return context['addressTranslations']
73055
def translate_docs(self, ds, **kwargs):
        
        for d in ds:
            self.map_doc(d, {}, self.invert_subject_object)

        return [self.translate_doc(d, **kwargs) for d in ds]
1292659
def help_center_article_translations_missing(self, article_id, **kwargs):
        ""
        api_path = "/api/v2/help_center/articles/{article_id}/translations/missing.json"
        api_path = api_path.format(article_id=article_id)
        return self.call(api_path, **kwargs)
546849
def doTranslate(option, urlOrPaths, serverEndpoint=ServerEndpoint, verbose=Verbose, tikaServerJar=TikaServerJar, 
                responseMimeType='text/plain',
                services={'all': '/translate/all'}):
    '''
    
    '''
    paths = getPaths(urlOrPaths)
    return [doTranslate1(option, path, serverEndpoint, verbose, tikaServerJar, responseMimeType, services)
            for path in paths]
837410
def import_translations(request, language):
	
	def _import_po_file(uploadedfile, lang):
		lines = []
		for line in uploadedfile:
			lines.append(line)
		num_lines = len(lines)
		
		prog_ctxt = re.compile(r"msgctxt\s+\"(?P<id>\d+)--(?P<model>\w+)--(?P<object_id>\d+)--(?P<field>\w+)\"")
		prog_msgid = re.compile(r"msgid\s+\"(?P<source_text>.+)\"$")
		prog_msgstr = re.compile(r"msgstr\s+(?P<trans>.+)")
		
		i = 0
		while i < num_lines:
			line = lines[i]
			result = prog_ctxt.match(line)
			if result:
				id = result.group("id")
				is_fuzzy = (lines[i-1] == "#, fuzzy\n")

				source_text = lines[i+1]
				translation_line = lines[i+2]

				# Traducción
				g = prog_msgstr.match(translation_line)
				if g is None:
					i += 1
					continue
				translation = g.group("trans").replace("msgstr","")[1:-1].replace("\\\"","\"").replace('\\\'','\'')
					
				# Obtención de la traducción a partir del id
				try:
					field_trans = FieldTranslation.objects.get(id=id)
				except FieldTranslation.DoesNotExist:
					source_text = source_text.replace("msgid","")[1:-1].replace("\\\"","\"").replace('\\\'','\'')
					source_md5 = hashlib.md5(source_text.encode("utf-8")).hexdigest()
					field_trans = FieldTranslation(model=result.group("model"), object_id=result.group("object_id"), field=result.group("field"), lang=lang, source_text=source_text, source_md5=source_md5)
					
				# Establecemos la traducción y si es fuzzy
				field_trans.translation = translation
				field_trans.is_fuzzy = is_fuzzy
				field_trans.save()
				#print translation
				#print is_fuzzy
				i += 4
			i += 1
	
	# Elimina traducciones que no estén asociadas a ningún objeto
	FieldTranslation.delete_orphan_translations()
	
	# Acceso obligatoriamente por POST
	if request.method != "POST":
		return HttpResponseRedirect(reverse("modeltranslation:admin_url"))
	
	form = ImportTranslationsForm(request.POST, request.FILES)
	if form.is_valid():
		_import_po_file(request.FILES['file'], language)
		#cache = TransCache.factory()
		#cache.clear()
		return HttpResponseRedirect(reverse("modeltranslation:view_all_url",args=(language,"all")))

	return HttpResponseRedirect(reverse("modeltranslation:admin_url"))
912128
def help_center_category_translations_missing(self, category_id, **kwargs):
        ""
        api_path = "/api/v2/help_center/categories/{category_id}/translations/missing.json"
        api_path = api_path.format(category_id=category_id)
        return self.call(api_path, **kwargs)
1223757
def get_obj_values(obj, translated_field_names):
        
        # set of translated fields to list
        fields = list(translated_field_names)
        values = {field: getattr(obj, field) for field in fields}
        return values
926635
def create_translations_for_item_and_its_children(self, item, languages=None):
        

        if not self.master:
            self.set_master(item)

        if not languages:
            languages = self.get_languages()

        result_ids = []

        # first process main object
        fields = self._get_translated_field_names(item)
        tasks = self.create_from_item(languages, item, fields)
        if tasks:
            result_ids += [task.pk for task in tasks]

        # then process child objects from main
        children = self.get_translatable_children(item)
        for child in children:
            fields = self._get_translated_field_names(child)
            tasks = self.create_from_item(languages, child, fields)
            if tasks:
                result_ids += [task.pk for task in tasks]

        return result_ids
31302
def help_center_articles_labels_list(self, locale=None, **kwargs):
        ""
        api_path = "/api/v2/help_center/articles/labels.json"
        if locale:
            api_opt_path = "/api/v2/help_center/{locale}/articles/labels.json"
            api_path = api_opt_path.format(locale=locale)
        return self.call(api_path, **kwargs)
975819
def help_center_section_translations(self, section_id, **kwargs):
        ""
        api_path = "/api/v2/help_center/sections/{section_id}/translations.json"
        api_path = api_path.format(section_id=section_id)
        return self.call(api_path, **kwargs)
267584
public ServiceCall<TranslationModels> listModels(ListModelsOptions listModelsOptions) {
    String[] pathSegments = { "v3/models" };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
    builder.query("version", versionDate);
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("language_translator", "v3", "listModels");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
      builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (listModelsOptions != null) {
      if (listModelsOptions.source() != null) {
        builder.query("source", listModelsOptions.source());
      }
      if (listModelsOptions.target() != null) {
        builder.query("target", listModelsOptions.target());
      }
      if (listModelsOptions.defaultModels() != null) {
        builder.query("default", String.valueOf(listModelsOptions.defaultModels()));
      }
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TranslationModels.class));
  }
1070453
def translate(self):
        
        translations = []
        for lang in settings.LANGUAGES:
            # do not create an translations for default language.
            # we will use the original model for this
            if lang[0] == self._get_default_language():
                continue
            # create translations for all fields of each language
            if self.translatable_slug is not None:
                if self.translatable_slug not in self.translatable_fields:
                    self.translatable_fields = self.translatable_fields + (self.translatable_slug,)

            for field in self.translatable_fields:
                trans, created = Translation.objects.get_or_create(
                    object_id=self.id,
                    content_type=ContentType.objects.get_for_model(self),
                    field=field,
                    lang=lang[0],
                )
                translations.append(trans)

        return translations
496187
def translate_resource_args(func):
    """"""
    @wraps(func)
    def wrapper(*args, **kwargs):
        """
        :type args: *Any
        :type kwargs: **Any
        :return: Any
        """
        arg_list = []
        for arg in args:
            if isinstance(arg, (Issue, Project)):
                arg_list.append(arg.key)
            else:
                arg_list.append(arg)
        result = func(*arg_list, **kwargs)
        return result

    return wrapper
190236
public function translate(Google_Service_Translate_TranslateTextRequest $postBody, $optParams = array())
  {
    $params = array('postBody' => $postBody);
    $params = array_merge($params, $optParams);
    return $this->call('translate', array($params), "Google_Service_Translate_TranslationsListResponse");
  }
557151
def view_all(request, language, filter=None):
	

	# Is there any filter?
	if request.method == "POST":
		data = request.POST.dict()

		if not data["search"] or data["search"]=="":
			return HttpResponseRedirect(reverse("modeltranslation:view_all_url",args=(data["language"],data["filter"])))

		return HttpResponseRedirect(reverse("modeltranslation:view_all_url",args=(data["language"],data["filter"]))+"?search="+data["search"])

	LANGUAGES = dict(lang for lang in settings.LANGUAGES)
	if language not in LANGUAGES.keys():
		raise Http404(u"Language {0} does not exist".format(language))
	
	if language == settings.LANGUAGE_CODE:
		raise Http404(u"El idioma {0} es el idioma por defecto".format(language))

	# Translation filter
	trans_filter = {"lang":language}
	if filter == "all" or filter is None:
		pass
	elif filter == "fuzzy":
		trans_filter["is_fuzzy"] = True
	elif filter == "completed":
		trans_filter["is_fuzzy"] = False
	
	search_query = ""
	if request.GET and "search" in request.GET and request.GET.get("search")!="":
		search_query = request.GET.get("search")
		trans_filter["source_text__icontains"] = search_query

	translations = FieldTranslation.objects.filter(**trans_filter)
	
	# Update translations
	active_translations = []
	for translation in translations:
		source_model = translation.get_source_model()
		if not translation.field in source_model._meta.translatable_fields:
			translation.delete()
		else:
			active_translations.append(translation)
	
	replacements = {"translations":active_translations, "filter":filter, "lang":language, "language":LANGUAGES[language], "search_query":search_query}
	return render_to_response('modeltranslation/admin/list.html',replacements, RequestContext(request))