0

I am looking for best practise patterns how to separate static phrases (e.g. button labels, status messages) from the actual template files when developing a custom theme? It is not necessary to make such phrases dynamically accessible as real WP content.

My research lead to the topic of internationalisation (http://codex.wordpress.org/I18n_for_WordPress_Developers). However, to me I18n appears a bit too much of an overhead for my purposes.

I am thinking of a separate phrases file which gets included, say, in header.php (or rather functions.php?). There, phrases would be defined and assigned to variables or constants, which could be used as place-holders in template files.

example file phrases.inc.php

define('SEARCH_BUTTON_TEXT', 'Search');
...
define('FILTER_SUCCESS_MESSAGE', 'Your filter results');

Any ideas?

  • 2
    I18n is best practice and isn't as much overhead as it seems. – Duane Jan 12 '16 at 9:59
  • 1
    Keep out of global scope (creating globals and constants), it is a really messy and evil place to be. Wordpress has already made a huge mess of this, don't go and dirty it even further. You should avoid creating globals and constants at all costs. As already stated, l18n is a much much better way and also the correct way of doing localization. – Pieter Goosen Jan 16 '16 at 10:32
  • Thanks, @Duane and PieterGoosen. That helps and I'd mark my question answered, if you'd be kind enough to create an answer out of your comments. – Bunjip Jan 19 '16 at 19:54
2

Your research lead you to the correct answer. Internationalization (A.K.A i18n) is best practice and is not as complicated as it may seem. You'll be better off in the long run learning it now.

@Pieter Goosen is 100% correct with his advise in response to your suggestion using variables and constants.

Keep out of global scope (creating globals and constants), it is a really messy and evil place to be. Wordpress has already made a huge mess of this, don't go and dirty it even further. You should avoid creating globals and constants at all costs. As already stated, l18n is a much much better way and also the correct way of doing localization.

  • Nice two-in-one answer ;-) – Pieter Goosen Jan 22 '16 at 10:16

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.