Support

Account

Home Forums ACF PRO Translate ACF fields in plugin with custom PO / MO

Unread

Translate ACF fields in plugin with custom PO / MO

  • I try to make my first WP plugin.
    I have included some lines from ACF into the SPOT-plugin.php that contain my plugin.

    I have made som PO / MO-files with Norwegian language for a plugin. SPOT-plugin.
    The line I want to include in the translations is this:
    ‘label’ => __(‘Please type the text here’, ‘spot-plugin’),
    ‘instructions’ => __(‘Max 100 characters’, ‘spot-plugin’),

    The text: ‘Please type the text here’ is the one I want to change with some a line from the PO / MO-file.
    The text: ‘Max 100 characters’ is the other line I want to change.

    I want to include this language files into the plugin so I don`t need to also have Polylang og Loco installed.

    See code below.
    What is wrong ? why can`t the code pickup the lines from the MO-files.

    <?php
    * Text domain: spot-plugin

    function spotplugin_init() {
    load_plugin_textdomain( ‘spot-plugin’, false, dirname(plugin_basename( __FILE__ ) ) . ‘/languages’ );
    }
    add_action( ‘plugins_loaded’, ‘spotplugin_init’ );

    /*
    * ———————————- *
    * Advanced Custom Fields
    * ———————————- *
    */
    // Define path and URL to the ACF plugin.
    define( ‘SPOT_PATH’, plugin_dir_path(__FILE__). ‘/includes/acf/’ );
    define( ‘SPOT_URL’, plugin_dir_URL(__FILE__) . ‘/includes/acf/’ );

    // Include the ACF plugin.
    include_once( SPOT_PATH . ‘acf.php’ );

    // Customize the url setting to fix incorrect asset URLs.
    add_filter(‘acf/settings/url’, ‘SPOT_settings_url’);
    function SPOT_settings_url( $url ) {
    return SPOT_URL;
    }

    // (Optional) Hide the ACF admin menu item.
    add_filter(‘acf/settings/show_admin’, ‘SPOT_settings_show_admin’);
    function SPOT_settings_show_admin( $show_admin ) {
    return true;
    }

    /*
    * ———————————- *
    * Advanced Custom Fields – Settings
    * ———————————- *
    */
    if( function_exists(‘acf_add_local_field_group’) ):

    acf_add_local_field_group(array(
    ‘key’ => ‘group_61fe7b4e4a219’,
    ‘title’ => ‘SPOT post’,
    ‘fields’ => array(
    array(
    ‘key’ => ‘field_61fe7b7a6fa6e’,
    ‘label’ => __(‘Please type the text here’, ‘spot-plugin’),
    ‘name’ => ‘SPOT-text’,
    ‘type’ => ‘textarea’,
    ‘instructions’ => __(‘Max 100 characters’, ‘spot-plugin’),
    ‘required’ => 0,
    ‘conditional_logic’ => 0,
    ‘wrapper’ => array(
    ‘width’ => ”,
    ‘class’ => ”,
    ‘id’ => ”,
    ),
    ‘default_value’ => ”,
    ‘placeholder’ => ”,
    ‘maxlength’ => ”,
    ‘rows’ => 3,
    ‘new_lines’ => ‘br’,
    ),
    ),
    ‘location’ => array(
    array(
    array(
    ‘param’ => ‘post_type’,
    ‘operator’ => ‘==’,
    ‘value’ => ‘post’,
    ),
    ),
    ),
    ‘menu_order’ => 0,
    ‘position’ => ‘normal’,
    ‘style’ => ‘default’,
    ‘label_placement’ => ‘top’,
    ‘instruction_placement’ => ‘label’,
    ‘hide_on_screen’ => ”,
    ‘active’ => true,
    ‘description’ => ”,
    ‘show_in_rest’ => 0,
    ));

    endif;

    ?>

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.