Ask question

Ask Questions and Get Answers from Our Community

Answer

Answer Questions and Become an Expert on Your Topic

Contact Staff

Our Experts are Ready to Answer your Questions

  • Upgrade your account to xenForo 2.x.x All Accesss Pass. Monthly subscription to the Premium group. Purchase a paid elevation of rights worth 30$ And Lifetime Upgrade 170$.

Phrase Replacements

lazarote

New member
Registered
Joined
Jun 24, 2019
Messages
10
Reputation
0
Points
1
Location
Cuba
Hi all,

If you've looked to replace various phrases within XenForo and felt frustated that no 'search and replace' function exists, you're in the same boat I am. I created a simple but straight forward script that does the job, in no way is it optimised but it does the job at hand.

The script is slightly tedious, and you'll need to open up your browsers Development Tools, then navigate to the 'console' area. If you're not sure, just google '<your browser> development tools' to find out.

Please read below the code for instructions on usage, this is the full code you'll be editing.

JavaScript:
for(el of document.querySelectorAll('[name=phrase_text]')) {
    var text = el.innerHTML;

    var fullPhrase = "";
    var words = text.split(" ");

    for(i = 0; i < words.length; i++) {
        var word = words[i];

        if(!word.includes("{") || !word.includes("}")) {
            word = word.replace("Oldword", "Newword");
            word = word.replace("oldword", "newword");
        }

        if(i == words.length) {
            fullPhrase+=word;
        } else {
            fullPhrase+=word + " ";
        }
    }

    el.innerHTML = fullPhrase;
    console.log(fullPhrase);
}


for(btn of document.querySelectorAll("button[class*=button--icon--save]")) {
    btn.click();
}
Ideally you will only be focusing on the following section:

Code:
      if(!word.includes("{") || !word.includes("}")) {
            word = word.replace("Oldword", "Newword");
            word = word.replace("oldword", "newword");
        }
Navigate to https://yourboardurl.com/admin.php?phrases/search, select the addon you wish to replace for, click "Refine Search" and click translate.

You may enter as many words as you wish to replace, eg if I wanted to replace "Resource", "Resources" with "Product", "Products" I would enter:

Code:
  if(!word.includes("{") || !word.includes("}")) {
            word = word.replace("Resource", "Product");
            word = word.replace("Resources", "Products");
        }
The phrases are paged, so you'll need to click across to either one.

I personally created this script as I had the struggle, and nothing in XenForo officially exists.

Thanks all.
 
Top