i18n-command icon indicating copy to clipboard operation
i18n-command copied to clipboard

Add VueJS support to wp i18n make-pot

Open sourovroy opened this issue 3 years ago • 5 comments

Add *.vue file support to wp i18n make-pot

Is there any plan to add VueJS support to wp i18n make-pot? Right now it doesn’t add those strings to pot file which are in *.vue

sourovroy avatar Jun 23 '22 14:06 sourovroy

There's an open feature request to allow customizing the list of file extensions. Right now only js and jsx are considered. See #231. But it might also make sense to extend the list of defaults to include more file extensions (e.g. also tsx, ts, etc.)

Do you perhaps have an example .vue file or even a repository that could be used to look into this further?

swissspidy avatar Jun 23 '22 14:06 swissspidy

Here is a sample App.vue file.

<template>
  <div>
    <h1>{{ __('VueJS Application', 'sourov-amvc') }}</h1>

    <nav class="sourov-amvc-nav">
      <ul>
        <li><router-link to="/">{{ __('Table', 'sourov-amvc') }}</router-link></li>
        <li><router-link to="/graph">{{ __('Graph', 'sourov-amvc') }}</router-link></li>
        <li><router-link to="/settings">{{ __('Settings', 'sourov-amvc') }}</router-link></li>
      </ul>
    </nav>

    <router-view></router-view>
  </div>
</template>

<script setup>
  const { __ } = wp.i18n;
</script>

sourovroy avatar Jun 23 '22 15:06 sourovroy

The command wp i18n make-json also needs the support for extracting *.vue strings from PO files.

sourovroy avatar Jun 24 '22 06:06 sourovroy

From what I can see this will probably require something similar to #304, involving the existing VueJsExtractor to extract these function calls from .vue files.

I currently have bandwidth to look into this myself, but any contribution in this area is more than welcome.

The command wp i18n make-json also needs the support for extracting *.vue strings from PO files.

This is covered by #231

swissspidy avatar Jun 24 '22 16:06 swissspidy

This is not specifically for wp-cli but if somebody wants a temporary solution, use the Loco Translate plugin to make a POT template, in the Loco plugin setting: "Scan JavaScript files with extensions:" use "ts Vue"

This takes really long to create a POT file but it includes text, maybe you guys can take some help from Loco's source code.

jeni1616 avatar Jul 07 '22 09:07 jeni1616

Your compiler must create bundled JS. So wp cli can scan bundled JS and extract pot and json file. I am using in vue and all works fine.

// Call functions.
const { __ } = wp.i18n;

export default {
    methods: {
         // Init WordPress i18n function to use in template.
        __,
    }
}

bilalmalkoc avatar Sep 10 '22 15:09 bilalmalkoc

Thanks @bilalmalkoc , It is working.

sourovroy avatar Sep 11 '22 04:09 sourovroy