Please make sure to update to WPML 4.3.5 and check our list of Known Issues before reporting

Hi, Amit here, I am the WPML Support Manager, our current ticket queue is high, update your WPML plugins and make sure you meet the minimal requirements for running WPML before reporting an issue please - many tickets are resolved doing that

Please look at our updated list of Known Issues and you can also use our support search to find helpful information and of course review our documentation before opening a ticket.

If you do need to open a ticket please make sure to provide us with all the needed information as described in this page

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Bruno 1 year, 2 months ago.

Assigned support staff: Bruno.

Author Posts
October 1, 2018 at 12:34 pm #2778116

miteshs

Hello,

I have created the custom options page for my plugin.
I want to make it WPML compatible. We have already done this functionality. But one thing we want to know.

How can we get the original site language?

For testing, we have created an options page with ACF Pro plugin
Please check below links.
hidden link
hidden link
When we save this options. WPML or ACF will be stored this option in options table, please check below links.
hidden link
here when I submit french option, it will be stored with the _fr_ language code.
But when we submit Spanish, this option will store without and language code.

Same thing we want to do with our custom options.
We want to know how we can get currently submitted language is original language? Is WPML stored original language for identification before add or update options?
We hope you can understand our issue. Let us know if you want more details from our side.

October 3, 2018 at 3:47 am #2783477

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello,

Thank you for contacting us. Please, my sincere apologies for the delay in answering.

I would be very happy to help you but I didn't fully understand what is the issue. Do you want to know which custom coding you should use to know the original language? If so, you can use the code below:

	global $sitepress;
	$default_language = $sitepress->get_default_language();
	echo $default_language;

If you want to take the default language, you can simply use the ICL_LANGUAGE_CODE constant.

If this is not what you are asking, can you please elaborate a little more so I can better understand? Sometimes screenshots illustrating what you mean may go a long way to clarify what words fail to transmit so if you like make use of "upload an image" below the comment area.

Thank you.

October 3, 2018 at 6:08 am #2783541

miteshs

Hello,

Thanks for your reply.

Sorry to say but it seems that you did not understand our concern.

global $sitepress;
$default_language = $sitepress->get_default_language();
echo $default_language;

the default language will change when I change default language from WPML -> languages -> Site Languages options, Please check below link.

hidden link

We want to get the source( original) language, or the site default language when WordPress installed.

Our goal is to create the new option for multiple languages.

like we have created one example option.
options_site_test_text

our default language when we have installed the WordPress is Spanish

Now we want to install this options with
english, Spanish, and French

For English we can use
update_option('options_en_site_test_text', 'Test English text');

For French we can use
update_option('options_fr_site_test_text', 'Test French text');

Now For Spanish, we need to insert options like this
update_option('options_site_test_text', 'Test Spanish text');

But how we can know that Spanish is the language when we installed the WordPress or Spanish is the primary source or original site language.

because we want to remove _es_ for spanish language.
update_option('options_site_test_text', 'Test English text');

October 3, 2018 at 9:43 pm #2785794

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello,

To get the language in which WordPress was installed, you can try looking in WPLANG:

$initial_language = get_option( 'WPLANG' );

If the value returned is blank, the default language is English. Otherwise, the language code will be returned.

Note that this option is changed in Settings > General > Site Language. Therefore, if this option is changed, the value in WPLANG will also change.

Also, note that this is a WordPress function with a WordPress registration. In this case, it is not related to WPML.

As a suggestion, you could add the language code in all functions with the update_option. For example:

update_option('options_en_site_test_text', 'Test English text');
update_option('options_fr_site_test_text', 'Test French text');

// note the "es"
update_option('options_es_site_test_text', 'Test Spanish text');

As a suggestion, you should keep the language code in all languages. If in the future you change the default code of your site this can cause a problem, for example, the default language does not have the language code.

In addition, I think WPLANG should resolve the issue you are reporting.

Thank you.

October 4, 2018 at 6:13 am #2786484

miteshs

Hello,

Thanks for your reply and suggestion.

$initial_language = get_option( 'WPLANG' );

The WPLANG value also update by WPML
from WPML -> languages -> Site Languages options
when I change the default language this option value update by WPML so this is not helpful to us.
hidden link
hidden link
hidden link

Here you have provided us the suggestion to add language code to options key.
As a suggestion, you could add the language code in all functions with the update_option. For example:

update_option('options_en_site_test_text', 'Test English text');
update_option('options_fr_site_test_text', 'Test French text');

//Note the "es"
update_option('options_es_site_test_text', 'Test Spanish text');

We think this is also not useful in the case
1) if already have option key installed in the database like
update_option('options_site_test_text', 'Test Spanish text');

after if I installed the WPML plugin then this suggestion will not work
2) if option key installed with language code in the database like
update_option('options_es_site_test_text', 'Test Spanish text');
and if I deactivate the WPML plugin, then this suggestion will not work

Our goal is we have created one plugin which has option page.
Now we want to make our plugin WPML compatible so we want to save options value with all the activate language by WPML.
like for example
update_option('options_en_site_test_text', 'Test English text');
update_option('options_fr_site_test_text', 'Test French text');
update_option('options_es_site_test_text', 'Test Spanish text');

Also Note: our plugin is already installed to clients websites, so we want to consider all the scenarios.

We think this is not a difficult question. We think WPML should store initial language when first time activates the WPML plugin, etc.

Also, we have checked the ACF Pro plugin for ( reference ) with creating option page and same example option they did this.

We request you to please provide the proper solution for how to make option page or costume option compatible with WPML?

Thanks

October 4, 2018 at 6:10 pm #2788529

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello,

Thank you for the explanation.

>>> We think this is not a difficult question. We think WPML should store initial language when first time activates the WPML plugin, etc.

I see no reason for this. If you want I can recommend this to our developers, but it does not make sense to simply save the initial language just to save.

This seems more like a custom coding, where you should then create a custom coding to do this. That is, at the time that WPML is configured, add a new option (add_option) to the current default language and just keep that information.

>>> We request you to please provide the proper solution for how to make option page or costume option compatible with WPML?

The WPML, by default, can easily translate the ACF option pages using the language selector in the top bar. To do this you need the ACF Multilingual and make the "Field Group" fields translatable.

You can see step by step in our documentation: https://wpml.org/documentation/related-projects/translate-sites-built-with-acf/

Then just switching the language using the language selector on the top bar should work correctly.

In your first post, I understood that you were wanting to create a custom code. So I suggested the previous steps. That is if you just want to translate the ACF options page, follow the steps below:

- Go to the https://wpml.org/documentation/related-projects/translate-sites-built-with-acf/
- Follow the steps in our documentation to:
-- Install the ACF Multilingual
-- Enable the "Fields Group" to be translatable
-- Duplicate the ACF Fields Group as shown in our documentation
- Go to the options page
- Switch to the secondary language
- Edit it to the desired values
- Click on the "Update" button

Following the steps above does this solve the problem? If indeed you do not want to use the ACF Multilingual, you will have to create some custom code to know the current language (which will be the initial language of the site) in the options field to later retrieve only this content.

Please, let me know if I can help with any other questions you may have. I'll be happy to help.

Thank you.