• Resolved 1name

    (@1name)


    Hey there,

    first of all, thanks a lot for your work on Sublanguage!
    So far it could provide any functionality I needed, but I fear that I just encountered a limitation to that:

    I am hosting a site with CPTs which have required custom fields (provided by ACF). Logically, they are part of the content and should give structured information on the respective entry. For proper display and comprehensibility, the data is output as a list of items formatted like this:
    {FIELD LABEL}: {FIELD VALUE}

    As there are different fields across the multiple CPTs, I implemented the ouput through a loop that prints the variables above. I didn’t hardcore output for every single custom field.

    Sublanguage gives me the possibility to offer multilingual input for the custom field’s value, but I couldn’t find any possibility to change the fields’ labels. Since the values are mostly names, I actually only need bilingual labels, no values!

    What I am looking for is an easy solution to have bilingual labels which WordPress/ACF/Sublanguage can handle correctly. I don’t know if it is possible to do this properly, so I wondered if it would be possible to use the field name property for one language and the field label property for another language and display one or the other according to the language that has been selected through the Sublanguage menu/widget.

    • This topic was modified 8 years, 2 months ago by 1name.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter 1name

    (@1name)

    Oh I just noticed that Sublanguage added a “Language Options” entry to the ACF admin menu, pointing to wp-admin/acf_language_option, which unfortunately is a dead link and breaks the standard ACF landing page as well :/

    Does this mean that what I require is already part of Sublanguage, only I need to fix this dead page issue? πŸ™‚

    • This reply was modified 8 years, 2 months ago by 1name.

    Hello,

    I understand what you want to do but I think your’re just going into bigger troubles if you go this way… I would just keep these field groups untranslated and hardcode the labels, its not that a big deal:

    
    $labels = array(
        'my_field_name' => __('My Field', 'my_domain'),
        'my_other_field_name' => __('My Other Field', 'my_domain'),
    );
    foreach ($items as $field_name => $field_value) {
        echo $labels[$label] . ' : ' .$value;
    }
    
    Thread Starter 1name

    (@1name)

    Hey Maxime,

    thanks for your quick reply!
    This sounds like a way better idea, but I can’t quite figure out yet how to implement it. I read through some l10n/i18n WP documentation but am still unsure, because the strings that I need to be translated are most likely not within any provided translation file.

    I’m totally new to the entire gettext/l10n/i18n topic, so I don’t know if I got this correctly but what I’m thinking about now is that I need to create my own .po/.mo files which have the few strings I am using plus my own translations of them, and then, in the respective function in my site-specific plugin, I call
    __($field['label'], 'my-text-domain')
    and WP will retrieve a string according to the language the user selected in the Sublanguage widget?

    Is this correct? πŸ™‚

    Edit: I am, furthermore, not sure if the approach we are talking about here is directly related to Sublanguage and should be in this forum. If so, I am sorry for occupying your time. If you don’t want to spend any more of it on helping me with my probably off-topic issue, feel free to tell me and I will move my question to stackexchange πŸ™‚

    • This reply was modified 8 years, 2 months ago by 1name.
    • This reply was modified 8 years, 2 months ago by 1name.
    • This reply was modified 8 years, 2 months ago by 1name.

    Actually you cannot pass any variable into the __() function. This sounds like an obvious idea but gettext just doesn’t work like that. Please check this resource to understand why: http://ottopress.com/2012/internationalization-youre-probably-doing-it-wrong/

    Then you’ll need a tool to actually translate your localized texts (as you say they probably wont be within any provided translation file). Poedit is a very common tool for that, but you need the pro (paid) version, the free version is quite useless. Otherwise there is a nice (and free) plugin for that: https://wordpress.org/plugins/loco-translate/

    Also you need to have a “/languages” directory in your theme directory. That’s were you will put your .po/.mo files, or where Loco Translate will put them. And have this code into the function.php file of your theme (if it isn’t already):

    
    add_action('after_setup_theme', function() {
        load_theme_textdomain( 'my-domain', get_template_directory() . '/languages' );
    });
    

    You can replace ‘my-domain’ by what you want but it must be the same as the ones in your localization functions: __('Some Text', 'my-domain)

    Hope this helps!

    Thread Starter 1name

    (@1name)

    Okay, after some hard-to-find-out differences between the current ACF free and premium versions, I was able to define the custom field groups “myself” in my site-specific plugin. This made it possible to declare the labels ready for localization, using the __() function πŸ™‚ Using Loco, I could then create a translation file and add the translations of the respective strings quite easily.

    The only thing, that is still giving me problems, are the strings of checkbox values – which I haven’t been able to translate effectively so far. I could enter translations for them in Loco, but the original strings are displayed when I switch language. I don’t think that this is possible with Sublanguage either, is it?

    Another problem that is even less related to Sublanguage but maybe interesting to any future readers of this thread: Now that I moved the ACF field group creation to my own site-specific plugin, they are not accessible from the ACF UI in the admin panel anymore. This might be problematic if you’re about to set up custom fields for someone else who should be able to change them later on.

    Thanks a lot for your help, Maxime! πŸ™‚

    • This reply was modified 8 years, 2 months ago by 1name. Reason: marked as resolved :)
Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Bilingual Custom Field Labels/Names?’ is closed to new replies.