Index a locale.

@param string $projectKey
@param string $localeId
@param array  $params

@return Index|ResponseInterface
182671
public function indexLocale(string $projectKey, string $localeId, array $params = [])
    {
        if (isset($params['tags'])) {
            $params['q'] = 'tags:'.$params['tags'];
            unset($params['tags']);
        }

        $response = $this->httpGet(sprintf('/api/v2/projects/%s/locales/%s/translations', $projectKey, $localeId), $params);

        if (!$this->hydrator) {
            return $response;
        }

        if ($response->getStatusCode() !== 200 && $response->getStatusCode() !== 201) {
            $this->handleErrors($response);
        }

        return $this->hydrator->hydrate($response, Index::class);
    }
826731
public String getMessage(String key, Locale locale)
	{
		if (null == locale)
		{
			return getMessage(key);
		}
		return CollectionTools.getString(getResourceBundle(locale), key, getBehaviourOnMissingMessage().getValueOnMissingMessage(key));
	}
1106017
@Route(method = HttpMethod.GET, uri = "i18n/bundles/{file<.+>}.json")
    public Result getBundleResourceForI18Next(@QueryParameter("locales") String listOfLocales,
                                              @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch) {
        // Parse the list of locale
        List<Locale> locales = new ArrayList<>();
        if (!Strings.isNullOrEmpty(listOfLocales)) {
            String[] items = listOfLocales.split(" ");
            for (String item : items) {
                // Manage the 'dev' value (it's the default locale used by i18next
                if ("dev".equalsIgnoreCase(item)) {
                    locales.add(InternationalizationService.DEFAULT_LOCALE);
                } else {
                    locales.add(Locale.forLanguageTag(item));
                }
            }
        }

        String etag;
        StringBuilder builder = new StringBuilder();
        for (Locale locale : locales) {
            builder.append(service.etag(locale));
        }
        etag = builder.toString();

        if (ifNoneMatch != null && ifNoneMatch.equals(etag)) {
            return new Result(Status.NOT_MODIFIED);
        }

        // i18next use a specific Json Format
        ObjectNode result = json.newObject();
        for (Locale locale : locales) {
            ObjectNode lang = json.newObject();
            ObjectNode translation = json.newObject();
            lang.set("translation", translation);
            Collection<ResourceBundle> bundles = service.bundles(locale);
            for (ResourceBundle bundle : bundles) {
                for (String key : bundle.keySet()) {
                    populateJsonResourceBundle(translation, key, bundle.getString(key));
                }
            }
            String langName = locale.toLanguageTag();
            if (locale.equals(InternationalizationService.DEFAULT_LOCALE)) {
                langName = "dev";
            }
            result.set(langName, lang);
        }
        return ok(result).with(HeaderNames.ETAG, etag);
    }
103751
public function fetchPackageTranslations($packageHandle, $packageVersion, $localeID, $formatHandle = 'mo')
    {
        $request = $this->buildRequest('package/' . rawurlencode($packageHandle) . '/best-match-version/translations/' . rawurldecode($localeID) . '/' . rawurldecode($formatHandle) . '/?v=' . rawurlencode($packageVersion));
        $this->httpClient->reset();
        $response = $this->httpClient->send($request);
        $this->httpClient->reset();
        $responseBody = $response->getBody();
        if ($response->getStatusCode() >= 400) {
            throw new Exception($responseBody);
        }

        return $responseBody;
    }
56482
public function get(string $projectKey, string $id, string $locale)
    {
        $response = $this->httpGet(sprintf('/api/translations/%s/%s?key=%s', rawurlencode($id), $locale, $projectKey));

        if (!$this->hydrator) {
            return $response;
        }

        if (200 !== $response->getStatusCode()) {
            $this->handleErrors($response);
        }

        return $this->hydrator->hydrate($response, TranslationModel::class);
    }
571639
public function findProperty($projectId, $propertyKey)
    {
        return $this->apiClient->callEndpoint(sprintf('%s/%s/properties/%s', self::ENDPOINT, $projectId, $propertyKey));
    }
218403
public function getHelpTextByKeyLocale($translationKey, $locale)
    {
        $qb = $this->createQueryBuilder('h');
        $qb->where('h.locale LIKE :locale')
            ->andWhere('h.translationKey LIKE :translationKey')
            ->orderBy('h.id', 'asc')
            ->setParameter(':locale', substr($locale, 0, 2).'%')
            ->setParameter(':translationKey', $translationKey.'%');

        try {
            $helpText = $qb->getQuery()->getSingleResult();
        } catch (NoResultException $e) {
            $qb = $this->createQueryBuilder('h');
            $qb->where('h.locale LIKE :locale')
                ->andWhere('h.translationKey = :translationKey')
                ->orderBy('h.id', 'asc')
                ->setParameter(':locale', substr($locale, 0, 2).'%')
                ->setParameter(':translationKey', 'not_found');
            $helpText = $qb->getQuery()->getSingleResult();
        }

        return $helpText;
    }
863565
public static function get($key, $default = null, $locale = null)
    {
        return self::all($locale)->get($key, $default);
    }
542625
public function addLocaleToJobSync($jobId, $localeId, AddLocaleToJobParameters $parameters)
    {
        $endpoint = vsprintf('jobs/%s/locales/%s', [$jobId, $localeId]);
        $requestData = $this->getDefaultRequestData('json', $parameters->exportToArray());
        $this->wait($this->sendRequest($endpoint, $requestData, self::HTTP_METHOD_POST));
    }
696434
protected function translate($key, $params = null, $language = null) {
		return Translation :: translate($key, $params, $language, $this -> getViewmodel());
	}
692808
public function download(string $projectKey, string $localeId, string $ext, array $params = [])
    {
        $params['file_format'] = $ext;

        $response = $this->httpGet(sprintf('/api/v2/projects/%s/locales/%s/download', $projectKey, $localeId), $params);

        if (!$this->hydrator) {
            return $response;
        }

        if ($response->getStatusCode() !== 200) {
            $this->handleErrors($response);
        }

        return (string) $response->getBody();
    }
1324626
private function loadI18nValues(&$firstResult, $params) {
        if (!$this->entity instanceof AbstractI18nEntity) {

            return;
        }
        $filter = array($this->entity->getI18nIdentifier() => $firstResult[0]['id']);
        $localesKey = 'locales';

        if (is_array($params) && array_key_exists('locale', $params)) {
            $filter['locale'] = $params['locale'];
            $localesKey = $params['locale'];
        }

        $this->getQueryBuilder()->where($filter);
        $query = $this->getQueryBuilder()->getQuery($this->entity, QueryBuilder::GET_ALL_ITEMS_QUERY, QueryBuilder::CHILD_ONLY);

        $i18nResult = $this->query($query);
        //file_put_contents('/var/www/shoppingcart/logs/test.log', '$i18nResult: '.print_r($i18nResult,true)."\r\n", FILE_APPEND);

        if ($localesKey == 'locales') {
            $firstResult[0]['locales'] = $this->getLocaleKeys($i18nResult, $this->getI18nValuesForPadding());
        } else {
            $firstResult[0]['locales'][$localesKey] = $i18nResult;
        }
    }
98583
protected function buildKey(
        $entityType,
        $entityId,
        $entityField,
        $locale
    ) {
        return $this->cachePrefix . '_' .
        $entityType . '_' .
        $entityId . '_' .
        $entityField . '_' .
        $locale;
    }
997580
public function create(string $projectKey, string $localeId, string $keyId, string $content, array $params = [])
    {
        $params['locale_id'] = $localeId;
        $params['key_id'] = $keyId;
        $params['content'] = $content;

        $response = $this->httpPost(sprintf('/api/v2/projects/%s/translations', $projectKey), $params);

        if (!$this->hydrator) {
            return $response;
        }

        if ($response->getStatusCode() !== 200 && $response->getStatusCode() !== 201) {
            $this->handleErrors($response);
        }

        return $this->hydrator->hydrate($response, TranslationCreated::class);
    }
513160
public function translate($key, $translation, $locale = null) {
        $this->translations[$this->locale($locale)][$key] = $translation;

        return $translation;
    }
885706
private void addToLocaleList(List localeList, List<Locale> locales) {
        if (locales != null) {
            for (Locale locale : locales) {
                if (locale != null && !localeList.contains(locale)) localeList.add(locale);
            }
        }
    }
849767
public function get(string $key): IndexInterface
    {
        if (!isset($this->indexes[$key])) {
            throw new IndexServiceException('Unknown index key: '.$key);
        }

        return $this->indexes[$key];
    }