-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlocale.php
69 lines (56 loc) · 2.75 KB
/
locale.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* ————————————————————————————————————————————————————————————————————————————————
* WEBTIGERS Copyright Notice
* ————————————————————————————————————————————————————————————————————————————————
*
* Copyright © 2020 WebTigers
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains the property of WebTigers.
* The intellectual and technical concepts contained herein are proprietary to
* WebTigers and may be covered by U.S. and Foreign Patents, patents in process, and
* are protected by trade secret or copyright law. Dissemination of this information
* or reproduction of this material is strictly forbidden unless prior written
* permission is obtained from WebTigers.
*
* See the LICENSE.txt for full licensing information governing the use of this
* information and software.
*/
/** Define a default locale. (Optional) */
defined('DEFAULT_LOCALE')
|| define('DEFAULT_LOCALE', 'en_US');
/**
* Define Locale Regex
* This is used to match specific routing where a locale is used in the URL.
*
* myapp.com/en_US/path/to/something
* myapp.com/en/path/to/something
*
* will automagically force / set the default locale for translation regardless
* of other user settings. Note that if you do not have any translations for the
* language, your bare translation keys will show. How embarrassing!
*/
defined('LOCALE_REGEX')
|| define('LOCALE_REGEX', '^[a-z]{2}(?:_[A-Z]{2})?$');
/** Attempt to discern if a locale exists within the first position of the uri string ... */
$uri_parts = explode('/', $_SERVER['REQUEST_URI']);
$locale_part = ( isset( $uri_parts[1] ) ) ? $uri_parts[1] : null;
$locale = ( Zend_Locale::isLocale( $locale_part ) )
? $locale_part
: 'auto';
/** If no locale URI string exists, check to see if we have a locale cookie set ... */
if ( $locale === 'auto' ) {
$locale = (isset($_COOKIE['locale']) && Zend_Locale::isLocale($_COOKIE['locale']))
? $_COOKIE['locale']
: 'auto';
}
/** Set our locale based on the existing locale or Zend's locale auto-detection. */
$locale = new Zend_Locale( $locale );
setcookie( 'locale', $locale->toString(), time()+(360*24*365), '/' );
/** Finally, set the locale as a constant and within the registry for other locale-aware components to find. */
Zend_Registry::set( 'Zend_Locale', $locale );
defined('LOCALE')
|| define('LOCALE', $locale->toString());
defined('LANG')
|| define('LANG', $locale->getLanguage());