Support

Account

Home Forums Backend Issues (wp-admin) Include ACF into theme and use translation

Solved

Include ACF into theme and use translation

  • Hi,

    if I include ACF into my theme the languages files in the “lang”-folder are not used and the backend is in original language.

    Is there a chance to get the translations to take effect.

    Thanks
    Thomas

  • Hi @Thomas

    Thanks for the bug report. Are you able to do some simple debugging in the acf.php file? Close to the top of the file, you will find the code to register the translation file.

    Perhaps this only works if ACF is used as a ‘plugin’.

    Maybe with some debugging you can discover what is wrong?

    Thanks
    Elliot

  • @elliot

    I see that and you could change the function you use to that one:

    
    load_textdomain('acf', dirname(__FILE__) . '/lang/acf-' . get_locale() . '.mo');
    
  • Hi @edir

    Nice find! I’ll add this to the to-do.


    @Thomas
    , are you able to test this out?

  • Great solution and it works!


    @elliot

    I have done the same with the new Options Page plugin and you should change it there, too.

    Would it not it be better to define a separate textdomain for the plugin (e.g. ‘acf-options-page’). Thus, potential conflicts with the ACF textdomain would not occur.

    I have done the German translation for the Options Page plugin (with the current textdomain ‘acf’) and enclosed it to this post. If you will change the textdomain, please let me know.

  • Hi @Thomas

    Thanks mate! I’ll add in the German translation and update the load_textdomain function as above.

    As for the text domain, I’m wanting to keep this as ‘acf’ for consistency and reading up on multiple text domains, it seems like WP will merge all the translations, so we won’t have any conflict issues.

    Thanks

  • @elliot
    I’m not sure if it’s a good solution. Look at ‘load_textdomain’ documentation: http://codex.wordpress.org/Function_Reference/load_textdomain and ‘load_plugin_textdomain’ http://codex.wordpress.org/Function_Reference/load_plugin_textdomain.

    Function ‘load_plugin_textdomain’ will megre multiple lang files for the same domain, ‘load_textdomain’ will not.

    In plugin ‘Options Page’, there is problem with loading transtaltions. Why? You use ‘load_plugin_textdomain’ for ‘acf’ domain, but ‘lang’ dir contains ‘acf-options-page.pot’ file. It’s name should be ‘acf.pot’. Similarly: ‘acf-options-page-pt_BR.mo’ should be ‘acf-pt_BR.mo’.

    Here is Polish translation for ‘Options Page’ plugin.

  • Hi @matczar

    Thanks for the info on this. Do you knwo of a solution which would allow someone to use ACF and ACF options page plugins as a theme inclusion. As in, not installed as WP plugins, but included in the functions.php file.

  • Oops,
    I did a deeper search and it turns out there is a difference between the description of these two functions in the documentation and code.
    Function ‘load_textdomain’ will also merge muliple .mo files for same domain: http://core.trac.wordpress.org/browser/tags/3.5.2/wp-includes/l10n.php#L310

    So edir is right.
    The function for use in the main plugin:
    load_textdomain('acf', dirname(__FILE__) . '/lang/acf-' . get_locale() . '.mo');
    and for use in add-ons, ex. ‘Optins Page’:
    load_textdomain('acf', dirname(__FILE__) . '/lang/acf-options-page-' . get_locale() . '.mo');

    I’ve tested this solution for normal and lite mode, and it works fine.

    P.S.
    If you want to use my translation files for ‘Options Page’ add-on, you should rename it:
    ‘acf-pl_PL.mo’ => ‘acf-options-page-pl_PL.mo’
    ‘acf-pl_PL.po’ => ‘acf-options-page-pl_PL.po’

  • Hi, has this been released as an update for ACF or do I still need to modify a file.

    I believe I am having the same issue. I have a German installation of wordpress but I want to be able to view the dashboard in English via the plugin wp native dashboard. This works for all plugins apart from ACF which remains in German. If I set the wp-config define lang to empty ”, then ACF returns to English, but remains in English when I change to German in the dashboard. So ACF is not behaving as other plugins do when the language is changed.

    Thanks for any advise.

  • Hi @cannedSunlight

    This code change will be included in the next version of ACF

  • In addition to this:

    $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); //theme_locale or plugin_locale, whether it is used in a theme or plugin

Viewing 12 posts - 1 through 12 (of 12 total)

The topic ‘Include ACF into theme and use translation’ is closed to new replies.