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?

3
  • 2
    I18n is best practice and isn't as much overhead as it seems.
    – Duane
    Commented Jan 12, 2016 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. Commented Jan 16, 2016 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
    Commented Jan 19, 2016 at 19:54

1 Answer 1

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.

1
  • Nice two-in-one answer ;-) Commented Jan 22, 2016 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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