Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Ignore locales; fix kebab-cased translation keys (#2433)
Olga Bulat04a36fcb3200
diff --git a/.eslintignore b/.eslintignoreindex a723c8c2e..c689aec76 100644--- a/.eslintignore+++ b/.eslintignore@@ -7,3 +7,5 @@ frontend/storybook-static!frontend/.storybook!.pnpmfile.cjs++frontend/src/locales/*.jsondiff --git a/frontend/src/locales/scripts/utils.js b/frontend/src/locales/scripts/utils.jsindex f4943825b..737f1c28b 100644--- a/frontend/src/locales/scripts/utils.js+++ b/frontend/src/locales/scripts/utils.js@@ -1,6 +1,8 @@const { writeFile } = require("fs/promises")const os = require("os")+const { camel } = require("case")+/*** Mutates an object at the path with the value. If the path* does not exist, it is created by nesting objects along the@@ -23,6 +25,18 @@ exports.setToValue = function setValue(obj, path, value) {o[a[0]] = value}+function replacer(_, match) {+ // Replace ###<text>### from `po` files with {<text>} in `vue`.+ // Additionally, the old kebab-cased keys that can still be in the+ // translations are replaced with camelCased keys the app expects.+ // TODO: Remove `camel` and warning once all translation strings are updated.+ // https://github.com/WordPress/openverse/issues/2438+ if (match.includes("-")) {+ console.warn("Found kebab-cased key in translation strings:", match)+ }+ return `{${camel(match)}}`+}+/*** Replace ###<text>### with {<text>}.*@@ -34,7 +48,7 @@ const replacePlaceholders = (json) => {return null}if (typeof json === "string") {- return json.replace(/###([a-zA-Z-]*)###/g, "{$1}")+ return json.replace(/###([a-zA-Z-]*)###/g, replacer)}let currentJson = { ...json }