2

There is a code added somewhere amongst Wordpress theme php files:

function functionFunction() {
  var ts = CRM.ts();
  theButton = 
  "<a id=thebutton href=/civicrm/contribute/transact/?reset=1&id=6>" 
  + ts("The Button to translate") 
  + "</a>";
  return theButton;    
}

A website is multisite + multilingual ( and none of the languages is English ), therefore The Button to translate needs to be translated to all enabled languages and be preserved during l10n updates.

There are some recipies here https://explore.transifex.com/civicrm/civicrm/ and and here https://docs.civicrm.org/dev/en/latest/extensions/translation/#for-developers-generate-po-and-mo-files-for-your-extension and also here https://github.com/civicrm/civistrings and there How to add additional custom translation for a payment processor?.

However none of these addresses the situation where we need to translate a few lines of text without messing with MO/PO, gettext/poedit, etc., etc. It looks like the closest one could get is to create an "empty" extension, the single purpose of which would be MO files accommodation - and even in this case we need to "merge" the extension translation file with the rest of it, which seems to be a bit too much for a small amount of text.

Am I missing something here? Any alternatives/workarounds/hacks/fast&dirty tricks?

7
  • That function is Javascript... is it really in your "theme php files"? Jul 11, 2023 at 9:30
  • @ChristianWach yes Sir, in wp-content/themes/mythemename/footer.php to be exact. Would it work if the code is moved somewhere else?
    – yurg
    Jul 12, 2023 at 7:21
  • Okay, so is the Javascript wrapped in a PHP function? I don't get how it would be used otherwise... indeed it would produce a PHP syntax error as it stands. Jul 13, 2023 at 9:00
  • 1
    Ah, scrap that, I see - it's in a template file not e.g. functions.php... okay... so @Demerit's answer should work, but I can add an alternative that references the WordPress locale (since that's the canonical one) if that helps? Jul 13, 2023 at 9:05
  • 1
    One other thought: since you are working with a WordPress theme, it's worth getting to know how to apply localisation and internationalisation to the theme. A good starting point is ottopress.com/2012/… It's not a quick fix for your issue, but will make your life much easier in future when working with multilingual WordPress installs. Jul 13, 2023 at 11:50

2 Answers 2

2

Following on from comments, if this is custom code then you can use CRM.config.locale and hardcode the translation there, e.g.

var text = 'banana';
if (CRM.config.locale == 'fr_FR') {
  text = 'banane';
} elseif (CRM.config.locale == 'de_DE') {
  text = ... etc
...
}
theButton = 
  "<a id=thebutton href=/civicrm/contribute/transact/?reset=1&id=6>" 
  + text 
  + "</a>";
1

Last I remember Administer - Customize - Word Replacements works for this it's just not obvious how to enter the text for the other languages. You need to switch to the language first then load the form. And the left hand side is always the en_US word.

3
  • Afraid this was the first thing I've tried in my naivety. Unfortunately this doesn't seem to be working for me at the moment.
    – yurg
    Jul 10, 2023 at 19:31
  • Oh ok maybe what I'm remembering is some work that was done to try to make it work that was not completed.
    – Demerit
    Jul 10, 2023 at 20:04
  • 1
    This is what I was thinking of - it wasn't completed: github.com/civicrm/civicrm-core/pull/15836
    – Demerit
    Jul 12, 2023 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.