soberwp / models

WordPress plugin to create custom post types and taxonomies using JSON, YAML or PHP files
MIT License
172 stars 13 forks source link

How to register label strings for translation? #19

Closed jorditarrida closed 6 years ago

jorditarrida commented 6 years ago

Hi,

I am using Models within a Roots Sage based theme. I followed the Sage instructions to generate a .pot file for translation, but the script does not register the label strings for translation. Is there any way to do it?

Thanks in advance for your help!

palmiak commented 6 years ago

Hey

Could you show us your file for models - it will be easier for us to help you.

If you are using the json or yaml files the reason they aren't translate is the fact that sage translate only php by default: "mkdir -p ./resources/lang && find ./resources ./app -iname '*.php'

To fix this take a look at https://www.tecmint.com/linux-find-command-to-search-multiple-filenames-extensions/

In case use are using php files - do you keep them in app directory?

jorditarrida commented 6 years ago

Hi @palmiak,

Thanks for your answer. I was originally using .json files so thanks to your comment I realized the easiest thing to do in this case was to use .php files. Although it is not documented, I used the gettext functions inside the .php file and when I ran yarn pot (following the instructions in my original post) the strings were properly registered for translation:

        'labels' => [
            'has_one' => __( 'Product', 'my-text-domain' ),
            'has_many' => __( 'Products', 'my-text-domain' ),
            'text_domain' => 'my-text-domain'
        ],

So I'll leave this here in case anyone else needs to do something similar.

Thanks again for your time! Jordi

darrenjacoby commented 6 years ago

Thanks for the explanation. I'll add this solution to the documentation soon.