Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Translations: wp i18n make-json produces no files #3298

Closed
psealock opened this issue Nov 24, 2019 · 12 comments · Fixed by #3433
Closed

Translations: wp i18n make-json produces no files #3298

psealock opened this issue Nov 24, 2019 · 12 comments · Fixed by #3433
Assignees
Labels
status: in progress type: bug The issue is a confirmed bug.

Comments

@psealock
Copy link
Collaborator

Describe the bug

The command npm run i18n creates a .pot file for translations. First, the js and then the php. The js gets overwritten by the php.

First reported in https://wordpress.org/support/topic/wordpress-i18n-how-to-translate-js-strings/

To Reproduce
Steps to reproduce the behavior:

  1. npm run i18n
  2. Check the resulting languages/woocommerce-admin.pot file for strings derived from js files, and see none exist.
  3. Run just the js this time, npm run -s i18n:js and see the js strings available in the same file.

Expected behavior
A clear and concise description of what you expected to happen.

I'm not an expert here, but it seems the js and php should be concatenated.

@psealock psealock added the type: bug The issue is a confirmed bug. label Nov 24, 2019
@rrennick
Copy link
Contributor

@psealock It merges them vs concatenate. If you npm run i18n in current master the second string in the file is

#: includes/connect-existing-pages.php:17 languages/woocommerce-admin.php:1863
#: src/Features/Analytics.php:142
msgid "Settings"
msgstr ""

The first 2 lines indicate locations where the string is found. languages/woocommerce-admin.php:1863 is the js strings

	// Reference: client/header/activity-panel/panels/orders.js:198
	// Reference: client/layout/controller.js:64
	__( 'Settings', 'woocommerce-admin' ),

@rrennick rrennick added the needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. label Nov 29, 2019
@psealock
Copy link
Collaborator Author

psealock commented Dec 1, 2019

I see! Thank you. I will close this one then.

@psealock psealock closed this as completed Dec 1, 2019
@yashk95
Copy link
Contributor

yashk95 commented Dec 2, 2019

Hello there,

Yes the mappings for JavaScript files are present in woocommerce-admin.php and in woocommerce-admin.pot, there are mappings for woocommerce-admin.php. But still, I am not able to translate any JavaScript strings.

Kindly mention the steps to translate them if you're able to translate.

--

Thanks

@rrennick
Copy link
Contributor

rrennick commented Dec 3, 2019

@yashk95
Copy link
Contributor

yashk95 commented Dec 3, 2019

@rrennick yes, I have already checked that. In this doc, it is mentioned that to translate the WooCommerce Admin plugin, we need to download .pot file from https://translate.wordpress.org/projects/wp-plugins/woocommerce-admin/ and yes this .pot file is correct but my question is that how to create this .pot file.

Kindly compare this .pot file from https://translate.wordpress.org/projects/wp-plugins/woocommerce-admin/ and the one which is generated by the command npm run i18n and see the difference by yourself.

@rrennick
Copy link
Contributor

rrennick commented Dec 3, 2019

but my question is that how to create this .pot file.

.po/.pot files have the generator in the header of the file. You can find that by opening the file in a text editor. The WordPress.Org generator is

"X-Generator: GlotPress/2.4.0-alpha\n"

Different tools may generate the file with strings in a different order. Eg.

GlotPress first string is on line # 17

msgid "The WooCommerce Admin feature plugin requires <a href=\"%1$s\">WooCommerce</a> %2$s or greater to be installed and active."

the result of npm run i18n has this string on line # 4576.

@yashk95
Copy link
Contributor

yashk95 commented Dec 10, 2019

Hello @rrennick

Kindly provide me the steps to create a .pot file.
I have done some modifications in the WooCommerce Admin plugin. In doing so, have added new strings in JavaScript files and want to generate a .pot file so that all those strings can be included with proper JavaScript mapping.

But if I run npm run i18n command, it doesn't even provide me the default WooCommerce Admin strings here with JavaScript mappings. It only provides me the mapping of PHP files so I can only translate the strings which are coming from PHP files in WooCommerce Admin plugin.

According to https://github.com/woocommerce/woocommerce-admin/blob/master/CONTRIBUTING.md#localizing-woocommerce-admin, i have to download the .po/.mo files from https://translate.wordpress.org/projects/wp-plugins/woocommerce-admin/.

Yes, if i download .po file from https://translate.wordpress.org/projects/wp-plugins/woocommerce-admin/, it has all the proper JavaScript mappings so I am able to translate all the JavaScript strings.

But my question is that how this .po file is created? As per my knowledge, .po file can only by generated by .pot file. So please let me know how i can generate the proper .pot file which has all the proper mappings so that i can generate it too for my modified WooCommerce Admin plugin.

--

Thanks

@rrennick
Copy link
Contributor

But if I run npm run i18n command, it doesn't even provide me the default WooCommerce Admin strings here with JavaScript mappings.

Yes, it does. See my explanation #3298 (comment) .

@yashk95
Copy link
Contributor

yashk95 commented Dec 11, 2019

I have seen your explanation and yes I know that there are JS mappings present in woocommerce-admin.php file and in woocommerce-admin.pot file, there are mappings of woocommerce-admin.php file but when you try to translate any JS string with this .pot, translation not done successfully. However, if you translate any PHP string like menus then it will get translated successfully.

Let me give an example for the translation. Kindly try translating word Analytics, it will get translated successfully and changes will get reflected in the site. Then try to translate the word Gross Revenue, it will get translated successfully because it is present in the .pot file but changes will not get reflected in the site.

I have tested this with the .pot file generated by npm run i18n.

@rrennick kindly test by yourself and let me know your views in this.

--

Thanks

@rrennick rrennick reopened this Dec 17, 2019
@rrennick rrennick changed the title Translations: JS strings overwritten by PHP in .pot file Translations: wp i18n make-json produces no files Dec 17, 2019
@rrennick rrennick self-assigned this Dec 17, 2019
@rrennick rrennick added status: in progress and removed needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. labels Dec 17, 2019
@rrennick
Copy link
Contributor

@yash-webkul Could you try out #3433 to see if that works for you?

@yashk95
Copy link
Contributor

yashk95 commented Dec 18, 2019

@rrennick thanks, yes it works for me now.

A little suggestion from side if you wish to apply, with command npm run i18n:json, you are replacing some mappings of development folder with the build one for .po file and then creating .json files. So instead of changing mappings in .po file, you can change the mappings directly in .pot file while generating it and just create .json file here.

Kindly let me know your views about this.

@rrennick
Copy link
Contributor

rrennick commented Dec 18, 2019

@yash-webkul Thanks for the followup. I explained the reason for delaying the mapping change with

The js pot file contains source references (which are useful for translators) while the json files are compiled based on the registered script handles of the dist/* files. Those references needed to be updated after translation but before making the json files.

Do translators use those source references? They are shown in the GlotPress edit screen
Screen Shot 2019-12-18 at 9 51 37 AM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: in progress type: bug The issue is a confirmed bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants