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

yarn translate:pot failing if public folder is generated #2672

Closed
4 tasks done
gmutschler opened this issue Apr 13, 2021 · 4 comments
Closed
4 tasks done

yarn translate:pot failing if public folder is generated #2672

gmutschler opened this issue Apr 13, 2021 · 4 comments
Labels

Comments

@gmutschler
Copy link

Description

There is an issue with the WP-CLI dependency, Peast (used to parse ES code). Anyhow the following error is thrown when parsing the content from public/script/app.js.

Warning: Uncaught Error in exception handling during call to Error::__tostring() in phar:///usr/local/Cellar/wp-cli/2.4.0/bin/wp/vendor/mck89/peast/lib/Peast/Syntax/Token.php on line 0

I don't believe it's a Sage issue in itself, but more a conflic between mck89/peast and the way Laravel Mix compile JS files.
Also we can get around it by temporarly removing the public folder, but a more robust workaround would be to ignore the public folder by adding the --exclude=\"public\" option in the yarn/npm script

Steps to reproduce

  1. Build your public folder with yarn build or yarn build:production
  2. Generate you translation file(s) with yarn translate:pot

Expected behavior: Should generate a .pot file in resources/lang/

Actual behavior: WP-CLI throw an error and the process exits with the code 255

Reproduces how often: 100%

Versions

Sage: 10.0.0-beta.1: TBA
OS: macOS 11.2.3

@gmutschler
Copy link
Author

gmutschler commented Apr 14, 2021

Ok apparently, wp i18n make-pot doesn't handle Blade template strings. I had to run wp acorn view:cache and to add the storage folder to --include option in order to have it working.

So my final yarn translate:pot in package.json looks like this :

{
  ...
  "scripts": {
    ...
    "translate:pot": "wp acorn view:cache && wp i18n make-pot . ./resources/lang/sage.pot  --ignore-domain --include=\"app,resources,storage\" --exclude=\"public\"",
    ...
  },
  ...
}

Sidenotes:

  1. Some /* translators: */ comments are missing in app/View/Composers/Post.php and resources/views/partials/comments.blade.php (as per https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#variables).
  2. wp i18n make-pot, throw a warning about a missing singular placeholder. I don't like it, but @Automattic/_s overcomes the warning this way. It's also recommended in the official doc.

@gmutschler gmutschler changed the title Sage 10: yarn translate:pot throwing failing if public folder is generated Sage 10: yarn translate:pot failing if public folder is generated Apr 14, 2021
@swalkinshaw swalkinshaw added this to the 10.0.0-beta.1 milestone Sep 7, 2021
@retlehs retlehs modified the milestones: 10.0.0-beta.2, 10.0.0-beta.3 Nov 19, 2021
@retlehs retlehs added the bug label Nov 19, 2021
@retlehs retlehs changed the title Sage 10: yarn translate:pot failing if public folder is generated yarn translate:pot failing if public folder is generated Dec 30, 2021
@SergiArias
Copy link

Following the duplicate bug I posted, to generate the pot file in the beta-2 (where cached views were moved to wp-content/cache/acorn/views) I used the following command:

wp acorn view:cache && wp i18n make-pot ../../ ./resources/lang/sage.pot --ignore-domain --include=\"themes/theme_folder/app,themes/theme_folder/resources,cache/acorn/views\" --exclude=\"themes/theme_folder/public,plugins,languages,upgrade,uploads,index.php\"

The only problem is having to update the theme_folder for every project, but it works ok.

Now is the only way to do it as plugins normally scan the theme folder only.

@StudioRATATA
Copy link

@SergiArias I've used wp i18n in beta1 as well. But it doesn't play well with beta2. But the devs published documentation about translations. I've tried this with my beta2 theme and it works well. I've tested it with your <h2>{!! __('Frequently asked questions', 'sage') !!}</h2> line in the app.blade.php and it got picked up in the pot file.

@SergiArias
Copy link

@StudioRATATA why wp i18n doesn't play well in beta2? It works flawlessly for me.

I tried also the way you recommend in the official documentation and it works except for one thing: In the "content-type" line of the pot file instead of UTF-8 it gives CHARSET. Does it happen to you as well?

Unfortunately I don't understand very well this command to propose a solution.

@retlehs retlehs modified the milestones: 10.0.0-beta.3, 10.0.0-beta.4 Jan 19, 2022
@SergiArias SergiArias mentioned this issue Jan 31, 2022
3 tasks
@retlehs retlehs closed this as completed Feb 10, 2022
@retlehs retlehs modified the milestones: 10.0.0-beta.4, 10.0.0-beta.3 Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants