1
votes

I am using custom fields (with the free version of ACF) to add additional, sometimes required, formatted content to the respective custom post type entries. I put together a little site-specific plugin which includes filters to add the custom fields to excerpt and content and puts them out, via a loop, as a list of:

{CUSTOM FIELD LABEL}: {CUSTOM FIELD VALUE}

The website should be available in English and German. Using the Sublanguage plugin, I could translate most of the website, but not the custom field labels.

From what I read on i18n/l10n and Wordpress, I understood that I should best use __() for the labels when creating the custom fields. Since custom field creation is realized by ACF plugin code, I assume I have to create the fields "myself" so that I can do multilingual labels using __(). I guess, I would then realize the actual translation of the fields with Loco Translate.

ACF offers a neat way to export my already existing ACF-created field groups, which provides me with the PHP code to create the fields "on my own". I put the ACF code inside a new function in my site-specific plugin and hooked it to the acf/init action. I did pretty much the same as described in this question, but nothing happens: When I trash the custom field groups within the ACF interface afterwards, no custom fields appear in the "new post" screen.

So basically, I am having one question that, depending on the answer, will spawn follow-up questions:

  • Is this how I should and can realize bi/multilingual custom field labels?
    • If no: How else would you implement bilingual custom field labels/names?
    • If yes: Am I hooking the function to the wrong action?

PS: I wasn't sure if this belongs here or in the WP StackExchange, since part of it is coding related and part of translation-logic-related. Please tell me if I should move it over to the other platform.

1

1 Answers

1
votes

Alright,

I was able to solve most of this myself in the meantime:

  • I did not hook into the correct action. As it turns out, acf/init is only available in ACFv5 (pro), while the free edition is still in version 4.x. I hooked into init - et voilĂ : there are my field groups.
  • Using __() functions to declare my custom fields' labels, Loco Translate made it quite easy to translate the strings myself.

Conclusion

Apparently, my assumptions were correct - this is how to create internationalized custom field labels :) Nevertheless, I wasn't able to effectively translate the options of a checkbox field I am using, although Loco recognized the string and I provided a translation.

However....

The solution is far from perfect:

  • I am now using two plugins to translate as much as possible on the website.
  • Creating the ACF field groups "myself" through PHP code in my site-specific plugin, I needed to remove them from the admin UI. This means, that it's going to be difficult for any standard users to change anything about them in the future (which might of course be a feature as well :))