themosis / framework

The Themosis framework core.
https://framework.themosis.com/
GNU General Public License v2.0
671 stars 121 forks source link

Text_domain issue #65

Closed ramon-villain closed 8 years ago

ramon-villain commented 9 years ago

Hello, I'm trying to fix the text_domain issue, but I'm not getting any success, I looked the code, and you're using the 'double-underscore-function' in PostTypeBuilder for internationalisation of the messages. But it stills showing me in English, even my language is set to Portuguese. For example the 'Add New'/'All' words in the PostTypeBuilder.

So do you have any idea how can we proceed?

load_plugin_textdomain(THEMOSIS_FRAMEWORK_TEXTDOMAIN, false, basename( dirname( __FILE__ ) ) . '/languages' );

I tried this in themosis.php, but I don't know if it works with mu-plugins, also tried the 'after_setup_theme' and 'init' loading, without success

jlambe commented 9 years ago

Hi,

I have to check for this. So you're trying to load a .mo file in order to translate post type admin messages.

Also, if you want to modify the default messages, you can overwrite the labels property of your custom post type:

$post = PostType::make('slug', 'Names', 'Name')->set(array(
    'labels' => array(
        'add_new' => __('Your translated label')
    )
));
ramon-villain commented 9 years ago

Ok, I'll overwrite them.

mediastuttgart commented 9 years ago

Hey,

Just tried to achieve something similar and ended up with adding load_theme_textdomain('my-theme-name) to the themosis functions.php file.

Second i changed the THEMOSIS_THEME_TEXTDOMAIN in the themosis functions.php file to match my theme name (renamed the original themosis theme as suggssted in the documentation).

Then i used poedit to scan the my-theme-folder/app to find all strings to be translated. After successfully scanning the directories poedit created the necessary languages files (my-theme-name-de_DE.mo + my-theme-name-de_DE.po) which i saved to the languages/my-theme-folder.

Finally everything was translated properly. Strings inside the menus.config.php for example were translated properly, too. I also was able to translate rewrite slugs from custom post types created with themosis (remember to flush rewrite rules to make them work, else you will receive a 404).

Though not sure if this is the right approach but seems to be close.

jlambe commented 9 years ago

Still haven't had the time to check this. For one project, I had no issues in translations but will need to verify.

You can also define constants using the constants.config.php file in your theme and use that constant for translation.

Regarding WordPress documentation, as best practice, it seems better to add a Text Domain: my-textdomain statement in your theme style.css comment declaration.

rluders commented 8 years ago

I'm having problems to load my theme language in 1.2.3. Can you give me a hand?

I just change the textdomain in config/application.config.pgp to 'mytheme'. After that I just create a .po and .mo file into mytheme/language and name it: pt_BR.po and pt_BR.mo.

In my view call the translation funcion: {{ _('mystring.text', 'mytheme') }} (I'm using PoEdit and scanning the string from storage/views)

jlambe commented 8 years ago

In current theme, the load_theme_textdomain() is not implemented into the functions.php, that's why your translation do not work currently. Add a after_setup_theme hook and call the localization function so WordPress can look after your translated files.

rluders commented 8 years ago

Julien, I added this code to my functions.php but nothing happens.

add_action('after_setup_theme', function() { load_theme_textdomain('pascar', get_stylesheet_directory() . '/languages'); });

Do you know if my .po/.mo files must have a specific name? I already try to use pt_BR and mydomain-pt_BR.

I'm using Polylang also, but I think it's not the problem.

jlambe commented 8 years ago

Try this code perhaps. But you can add in the bootstrap/start.php file instead or at least after the definition of the constant THEMOSIS_TEXTDOMAIN:

add_action('after_setup_theme', function()
{
    load_theme_textdomain(THEMOSIS_TEXTDOMAIN, get_template_directory().'/languages');
});
rluders commented 8 years ago

I'm doing something really wrong here. I put your code, just after THEMOSIS_TEXTDOMAIN definition, but it still not working.

rluders commented 8 years ago

I try to debug to verify if my language file is loading. Then I use the code add_filter('load_textdomain_mofile', function($mo) { exit($mo); });

Ok. It really give me the path to my .mo file inside the theme. But still not printing the traslated string.

rluders commented 8 years ago

Done! :+1:

Permission problem.

jlambe commented 8 years ago

Fixed and will be available for release 1.3.0.