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

Make theme JS translatable #71

Open
davekiss opened this issue Nov 3, 2020 · 0 comments
Open

Make theme JS translatable #71

davekiss opened this issue Nov 3, 2020 · 0 comments

Comments

@davekiss
Copy link
Collaborator

davekiss commented Nov 3, 2020

"Search videos…"
"Download Video"
"Filed under" [for tags],
"xx views"
"page x of y"

Make these strings translatable with Loco Translate plugin in any Vimeography gallery theme

Implementation

1.) Add 'wp-i18n' script dependency

wp_register_script( 'my-handle', plugins_url( '/js/my-file.js', MY_PLUGIN ), array( 'wp-i18n' ) );

2.) Use translation helpers in the JS file

const { __, _x, _n, _nx } = wp.i18n;

__( '__', 'my-domain' );
_x( '_x', '_x_context', 'my-domain' );
_n( '_n_single', '_n_plural', number, 'my-domain' );
_nx( '_nx_single', '_nx_plural', number, '_nx_context', 'my-domain' );

3.) Tell WP that your script handle requires a specific text-domain
wp_set_script_translations( 'my-handle', 'vimeography' );

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

No branches or pull requests

1 participant