Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this the correct path for translations? #590

Open
DAnn2012 opened this issue Feb 17, 2025 · 5 comments
Open

Is this the correct path for translations? #590

DAnn2012 opened this issue Feb 17, 2025 · 5 comments

Comments

@DAnn2012
Copy link
Contributor

Hello.

Is this the correct path for the .mo files with the translations?

load_textdomain( LP_TEXT_DOMAIN, WP_LANG_DIR . '/learnpress/learnpress-' . $locale . '.mo' );

Should the correct path be WP_LANG_DIR . '/plugins/learnpress-' . $locale . '.mo' or not?

Thanks.

@tungnxt89
Copy link
Collaborator

Hi DAnn2012,

Code handle load textdomain of LP is correct. Not like you recomment. Because LP not provide file .mo, only file .po. To The system of Wordpress handle to create file .mo for when you choose a language. You can read code of Woocomerce too.

Thanks.

@DAnn2012
Copy link
Contributor Author

Hi tungnxt89,

Thank you for your reply and explanation.

But I noticed that recently the WooCommerce code was updated and it has both (and it loads them if there is a custom translation):

woocommerce/woocommerce@9f9c427

Thanks.

@tungnxt89
Copy link
Collaborator

Hi DAnn2012,

Thank you for your infomation, we'll check it.

Thanks.

@tungnxt89
Copy link
Collaborator

tungnxt89 commented Feb 24, 2025

Hi DAnn2012,

If on method load_plugin_text_domain, we run only: load_plugin_textdomain( 'learnpress', false, LP_PLUGIN_FOLDER_NAME . '/languages' );. Not use load_textdomain, it is correct?

About Woo, woocommerce/woocommerce@9f9c427. Currently, this code not apply for release version. And don't understand why need to write it, we think Wodpress have code to do that.

Thanks.

@DAnn2012
Copy link
Contributor Author

Hi @tungnxt89

I did some tests.

Currently LearnPress first searches for the file with the translation in the custom path, for example "wp-content/languages/learnpress/learnpress-es_ES.mo" and then alternately for the translations generated by translate.wordpress.org, for example "wp-content/languages/plugins/learnpress-es_ES.mo". If it finds the file in the custom path, it loads it with the custom translations and for the missing translations it shows the strings in English. If it does not find it, it loads the one generated by translate.wordpress.org.

If instead in the code you insert both "load_textdomain" with the two paths as in the next updates of WooCommerce, if it finds the file in the custom path, it loads it with the custom translations and for the missing translations it loads the one generated by translate.wordpress.org.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants