redux-framework icon indicating copy to clipboard operation
redux-framework copied to clipboard

Translate the contents of sample-config.php with different language domain

Open vertigo7x opened this issue 13 years ago • 9 comments

Hi! i've been working a lot with the translation of my theme and also with my config file of Redux. I dont know why, but all the translated elements that belongs to the config file doesn't get translated. I think this is because of the different way to read language files for themes and plugins, but I cant figure out how to do it correctly.

Also, one thing I notice is at the constructor of the ReduxFramework class, the _internationalization method is called on wp_load action. I suggest to change this to the init action, as it is considered a good practice for plugins:

// Load plugin text domain add_action( 'init', array( &$this, '_internationalization' ) );

Thanks for this great work, and some light on this will be apreciated!

vertigo7x avatar Nov 07 '13 19:11 vertigo7x

Im getting mad on this!

I have declared my text domain as cv_country on the styles.css and on the functions.php from my theme. And I get it to work on the text from sample-config.php as cv-country. Why?????!

It works on the theme files, and work as mentioned on the config from redux!!!1

vertigo7x avatar Nov 07 '13 20:11 vertigo7x

so it works in redux, but not your theme?

dovy avatar Nov 07 '13 20:11 dovy

this is our international string that works in both plugin and theme...

 public function _internationalization() {

            $domain = 'redux-framework';
            $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
            load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' );
            load_textdomain( $domain, dirname( __FILE__ ) . '/languages/' . $domain . '-' . $locale . '.mo' );

        }

dovy avatar Nov 07 '13 20:11 dovy

Let me explain: I declared my text domain with an underscore (cv_country)and I get it working on my theme with the underscore. But, when I try to translate the contents of my redux config file, I get a translation if I use a dash (cv-country). My theme locale files are created following the standarts. In this case, for spanish, locale code is es_ES. My .po file includes my theme files gettext and the config for Redux. Is there any mistake? Did I miss something?

Edit: After some checking, I see some text wont get translated even with the dash version of the text domain. Edit 2: After another check, the untranslated texts from before, weren't translated by in the .po file. My fault. But the dash - underscore problem is still there.

vertigo7x avatar Nov 07 '13 20:11 vertigo7x

I have to be honest, I know very little of wordpress translating. All we've done is just from me doing some quick searches. I am not exactly sure how I got it to work, haha.

Let me give you some pointers though.

  1. Use a variation of the above.
  2. DO NOT store you config file inside the ReduxFramework folder at all. There could be cross-over.
  3. Perhaps there is a limitation of underscores vs dashes. I don't know you'd have to look it up.

If you can provide me a zip, I'll try to help when I have a free moment. [email protected]

Yea, internationalisation is a pain in the A**, that's for sure.

dovy avatar Nov 07 '13 23:11 dovy

OMG, this is getting me crazy! After some more research, I found two things. First, the Text Domain declaration in the style.css is enouhg to translate a theme, there is no need to load language files manualy. Second, if I choose to declare my text domain like this: cv-country. It wont work. I found in wordpress Codex some information about the headers in the files must be letters (a-z A-Z), but no info about underscores or dashes. If I choose to use the underscore variation, it works, but just with some texts. I change manually two or three text with the underscore version of the text domain (cv_country) and it works, but if I do a Search & Replace all over the config file, it stop working. WHY?!?!?!!!

RE: Dovy, I have the config file inside the inc folder of my theme.

vertigo7x avatar Nov 07 '13 23:11 vertigo7x

Well, let's skype/gchat tomorrow and I'll see if I can help. I'll need your source files though.

Skype: dovydigital GChat: [email protected]

dovy avatar Nov 08 '13 06:11 dovy

Well, finally I get it. Some of the code I left behind in the sample-config.php was causing a bad translating behaviour. I was changing step by step each transformation ( __("some text") ) and I found the problem. Dont perform concatenation of strings without the use of sprintf or printf. For the line where you write the sentence "Did you know that Redux sets a global variable for you...". You included a concatenation with the $v variable. If you try to translate your panel and perform a concatenation like this, this cause a no translation behaviour. Solution, do it like this:

sprintf( __('<p>Did you know that Redux sets a global variable for you? To access any of your saved options from within your code you can use your global variable: <strong>$%1$s</strong></p>', 'your-language-domain' ), $v );

Maybe this is too newbie in the terms of translating a theme, but Im sure it will cause some headaches in the future. Hope this helps someone! And dovy, thanks for the support :) Lets talk other day!

vertigo7x avatar Nov 08 '13 07:11 vertigo7x

Ha, that's good to know! I usually would just do:

<?php
$args['intro_text'] = __('<p>Did you know that Redux sets a global variable for you? To access any of your saved options from within your code you can use your global variable:', 'redux-framework'). '<strong>'.$v.'</strong></p>';

Sorry that your problem with translation was our sloppy work. I've added the sprintf to the demo file so others can learn from your efforts.

Thanks.

dovy avatar Nov 08 '13 13:11 dovy