0

I usually store language files in /languages folder that is located in theme folder and it's also recommended location by WordPress as well. However, it still doesn't look like the best solution because files will be overwritten after theme updates.

load_theme_textdomain function allows to specify a different location and I've been thinking to put languages folder inside of /uploads folder in order to prevent overwriting after theme updates. That folder will be created right after theme activation and language files will be copied there.

My question is, do you think this is a good solution or there is a better way that I'm missing?

I appreciate your insight about this matter.

2

Own theme

If you are using your own theme, no need to worry about, because /languages folder is in your control that way. :)

Other's theme

But your concern is about other's theme and you want to apply your translations into that theme, then the best way is to make a Child Theme. Because you are actually modifying that theme. Make your languages files and put them into your child theme's /languages/ folder, and that's all.

If the parent theme is already translation-ready, it'll catch everything. But if it's not, then make a functions.php and show the translation-files' path:

load_theme_textdomain( 'theme-textdomain', get_stylesheet_directory() . '/languages' );

Note the get_stylesheet_directory() here, it's because we are showing the active theme's path. :)

  • Awesome! I wasn't so sure about child theme allows to control localization files. Great info, thanks for your help! – Mertafor Apr 16 '15 at 5:58
  • By the way one last detail : re-scanning file. For example theme has a new update and there are new lines that require to be translated in theme files. Obviously it'll require to re-scan theme folder through POEdit. In that case, will .mo file that is located in child theme catch changes in parent theme folder? – Mertafor Apr 16 '15 at 6:10
  • I haven't tried. You better try once in localhost with two dummy themes and let us know. If it's not, then after theme update, put the .mo file into parent theme, produce your .po and then put 'em back to your child theme. :) – Mayeenul Islam Apr 16 '15 at 6:12
  • I see, I'll look into it Mayeenul. Even the worst case scenario to re-scan in parent theme then move back to child theme is good idea. Thanks again! – Mertafor Apr 16 '15 at 6:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.