localization.php 635 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. function printtext($key) {
  3. echo TEXTS[$key];
  4. }
  5. function printftext() {
  6. $argv = func_get_args();
  7. $key = array_shift($argv);
  8. return vprintf(TEXTS[$key], $argv);
  9. }
  10. // default to language "en"
  11. $locale = "en";
  12. if (array_key_exists("HTTP_ACCEPT_LANGUAGE", $_SERVER)) {
  13. $accept_language_header = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  14. foreach(explode(",", explode(";", $accept_language_header)[0]) as $header_language) {
  15. if (file_exists("locale/$header_language.php")) {
  16. $locale = $header_language;
  17. break;
  18. }
  19. }
  20. }
  21. define("TEXTS", require_once "locale/$locale.php");
  22. ?>