Best way to translate options page
Support › MB Settings Page › Best way to translate options pageResolved
- This topic has 4 replies, 3 voices, and was last updated 6 years, 10 months ago by
anja.
-
AuthorPosts
-
August 14, 2018 at 4:27 PM #11004
Bezzo
ParticipantHello,
I'm not sure if it is a good place to ask. I'm using WPML and I'm wondering if there's an option to translate custom setting page like normal page. I've create custom plugin which includes metabox via composer. Also I've created wpml-config.xml file and fields I've registered ale capable of translation but not in user friendly way.

These fields can be translated via "String translation" menu page in WPML. Moreover there's raw HTML in these fields which is generated form WYSIWYG field so "regular" user can be confused. I would like to achieve something like normal page

I'm not sure if it is possible or just I don't know how to do that.
I know that ACF PRO allow you to "separate" custom fields in settings page depended on language.
Right now with metabox if I switch languages in my settings page content of fields is the same and changing it changes fields globally.
August 16, 2018 at 2:01 PM #11019Anh Tran
KeymasterHi Bezzo,
Interesting question! Thanks for asking this.
Using
wpml-config.xmlis the standard way and is recommended by WPML. However, if you need to have different settings per language, you can use theICL_LANGUAGE_CODEconstant to detect current language and set the field IDs based on that.This is the sample code:
$prefix = ICL_LANGUAGE_CODE . '_'; $meta_boxes[] = [ 'title' => 'Fields', 'fields' => [ [ 'id' => $prefix . 'text', 'name' => 'Text', 'type' => 'text', ], // Other fields. ], ];To get the field value, you can create a helper function like this:
function my_setting( $field_id ) { $option_name = 'my_option'; $field_id = ICL_LANGUAGE_CODE . '_' . $field_id; // Prepend the language code. return rwmb_meta( $field_id, array( 'object_type' => 'setting' ), $option_name ); }December 11, 2018 at 12:05 AM #12581anja
ParticipantI also have an extra settings page and WPML in use.
I created it with the Page Builder.
How can I translate the fields now?Settings page
https://abload.de/img/bildschirmfoto2018-12qxfh0.pngCode in the template
https://abload.de/img/bildschirmfoto2018-12w3fdw.pngResult on the front page
https://abload.de/img/bildschirmfoto2018-1277etz.pngDecember 12, 2018 at 5:15 PM #12619Anh Tran
KeymasterHi anja,
Please follow the instruction in the previous reply and the WPML documentation.
December 12, 2018 at 9:50 PM #12628anja
ParticipantAnd how can I use "$prefix" in the "MB Builder" plugin?
-
AuthorPosts
- You must be logged in to reply to this topic.