Custom Code to Translate Noloco


Translate Noloco-Apps to another language by manipulating DOM elements via JavaScript custom code


HOW TO USE:

  • Insert the desired translations in the marked places to replace the English terms defined above.
  • Remove all comments (not mandatory for functionality, but recommended), with the exception of "<script>" and "</script>" at the beginning and at the end of the code.
  • To do this, simply delete the marked lines.
  • Copy the remaining code and paste it into your Noloco app: Settings -> Custom Code -> Footer code


DESCRIPTION:

  • function translate :Is the function that contains the commands to manipulate the DOM elements.Is the function call to execute the translate function when the page is loaded

  • setInterval(translate, 333); Is an interval function which calls translate again in the defined interval.This is necessary because some elements in your Noloco-App are regularly updated and reloaded.




<script>
setInterval(translate, 333);

function translate() {

for (const parent of document.querySelectorAll("span")) {

for (const child of parent.childNodes) {

if (child.data == "Save") {

child.data = "placeholder";

}

if (child.data == "Edit") {

child.data = "placeholder";

}

if (child.data == "Done") {

child.data = "placeholder";

}

if (child.data == "Or") {

child.data = "placeholder";

}

if (child.nodeValue && child.nodeValue.includes("Showing")) {

child.nodeValue = child.nodeValue.replace("Showing", "placeholder").replace("of", "placeholder").replace("results", "placeholder")

}

if (child.data == "Send a message") {

child.data = "placeholder";

}

}

}

for (const parent of document.querySelectorAll("button")) {

for (const child of parent.childNodes) {

if (child.data == "Confirm") {

child.data = "placeholder";

}

if (child.data == "Cancel") {

child.data = "placeholder";

}

if (child.data == "Sign out") {

child.data = "placeholder";

}

if (child.data == "Next") {

child.data = "placeholder";

}

if (child.data == "Sign in") {

child.data = "placeholder";

}

if (child.data == "Email me a recovery link") {

child.data = "placeholder";

}

if (child.data == "Previous") {

child.data = "placeholder";

}

}

}

for (const parent of document.querySelectorAll("a")) {

for (const child of parent.childNodes) {

if (child.data == "View profile") {

child.data = "placeholder";

}

if (child.data == "Forgot your password?") {

child.data = "placeholder";

}

}

}

for (const parent of document.querySelectorAll("h2")) {

for (const child of parent.childNodes) {

if (child.data == "Sign in to your account") {

child.data = "placeholder";

}

if (child.data == "Recover your password") {

child.data = "placeholder";

}

}

}

for (const parent of document.querySelectorAll("h3")) {

for (const child of parent.childNodes) {

if (child.data == "Magic link sent!") {

child.data = "placeholder";

}

if (child.data == "Use your password to sign in") {

child.data = "placeholder";

}

}

}

for (const parent of document.querySelectorAll("p")) {

for (const child of parent.childNodes) {

if (child.nodeValue && child.nodeValue.includes("We have sent an email to")) {

child.nodeValue = "placeholder";

}

else if (child.nodeValue && child.nodeValue.includes("Just click the link in the email to sign in!")) {

child.nodeValue = "placeholder";

}

if (child.nodeValue && child.nodeValue.includes("If we find your account we will send you an email with more instructions. Just click the link if you get it")) {

child.nodeValue = "placeholder";

}

}

}

for (const parent of document.querySelectorAll("label")) {

for (const child of parent.childNodes) {

if (child.data == "Email address") {

child.data = "placeholder";

}

if (child.data == "Your email") {

child.data = "placeholder";

}

}

}

for (const parent of document.querySelectorAll("li")) {

for (const child of parent.childNodes) {

if (child.data == "Text length should be equal to 4 characters") {

child.data = "placeholder";

}
}

}

for (const parent of document.querySelectorAll("input")) {

if (parent.placeholder == "Password") {

parent.placeholder = "placeholder";

}

if (parent.placeholder == "lisa@example.com") {

parent.placeholder = "placeholder";

}

if (parent.placeholder == "Search...") {

parent.placeholder = "placeholder";

}

}

}
</script >



Community Translations

These translations have been developed, built and maintained by some of the Noloco community.
If you do use this script and end up with a translation file, please let us know if you're happy to share it.


France Flag French



Portugal Flag / Brazil Flag Portuguese




Sweden Flag Swedish