/** * Update translation for the given locale. * * @param keyName key name * @param representation translation representation * @return status code 204 (no content) or 404 (not found) if key or target translation is null. */ @PUT @Path("/{key}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @RequiresPermissions(I18nPermissions.TRANSLATION_WRITE) public Response updateTranslation(@PathParam("key") String keyName, TranslationRepresentation representation) { WebAssertions.assertNotNull(representation, "The translation should not be null"); TranslationValueRepresentation translationToUpdate = representation.getTarget(); WebAssertions.assertNotNull(translationToUpdate, "The translation target should not be null"); Key key = keyRepository.get(keyName).orElseThrow(() -> new NotFoundException("The key is not found")); key.addTranslation(locale, translationToUpdate.getTranslation(), translationToUpdate.isApprox()); keyRepository.update(key); return Response.noContent().build(); } }
/** * Updates a key with the translation in the default language. * * @param representation key representation * @return key representation * @throws URISyntaxException if the URI is not valid. */ @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @RequiresPermissions(I18nPermissions.KEY_WRITE) public Response updateKey(KeyRepresentation representation) throws URISyntaxException { WebAssertions.assertNotNull(representation, THE_KEY_SHOULD_NOT_BE_NULL); WebAssertions.assertNotBlank(representation.getDefaultLocale(), THE_KEY_SHOULD_CONTAINS_A_LOCALE); Key key = loadKeyIfExistsOrFail(); key.setComment(representation.getComment()); key.setOutdated(); // Updates the default translation key.addTranslation(representation.getDefaultLocale(), representation.getTranslation(), representation.isApprox()); keyRepository.update(key); return Response.ok(new URI(uriInfo.getRequestUri() + "/" + keyName)) .entity(keyFinder.findKeyWithName(keyName)).build(); }