V
V
veroni13372021-11-25 11:14:34
WordPress
veroni1337, 2021-11-25 11:14:34

How to translate Carbon fields using WP multilang?

How to translate Carbon fields using WP multilang. This plugin supports ACF, how can I make Carbon support?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kulikov, 2022-01-05
@veroni1337

First option:

function carbon_lang_prefix() {
  $current = wpm_get_language();
  $prefix = '';
  if ( ! $current ) {
    return $prefix;
  }
  if ( $current == 'ru') {
    return $prefix;
  }
  $prefix = '_' . $current;
  return $prefix;
}

Like this. We have made a function that adds a prefix to the field name.
Create a field:
Field::make( 'text', 'footer_kop' .carbon_lang_prefix() , 'Copyright in the footer' )->set_width( 50 ),
To display the fields, you will also need to use this function next to the field name.
echo carbon_get_theme_option( 'footer_kop' .carbon_lang_prefix() );
spoiler
Функцию взял с сайта https://misha.agency/wordpress/carbon-fields-polyl... и немного изменил

----
Second option:
By the way, I came across a ready-made solution in the cf v2.2.0 , v3.0.0 documentation :
function crb_get_i18n_suffix() {
    $suffix = '';
    if ( ! defined( 'ICL_LANGUAGE_CODE' ) ) {
        return $suffix;
    }
    $suffix = '_' . ICL_LANGUAGE_CODE;
    return $suffix;
}

function crb_get_i18n_theme_option( $option_name ) {
    $suffix = crb_get_i18n_suffix();
    return carbon_get_theme_option( $option_name . $suffix );
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question