-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLanguage.php
executable file
·99 lines (58 loc) · 2.32 KB
/
Language.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
class Zaape_Language extends Zend_Controller_Plugin_Abstract{
public function fullUrl($url) {
$request = Zend_Controller_Front::getInstance()->getRequest();
$url = $request->getScheme() . '://' . $request->getHttpHost() . $url;
return $url;
}
public function preDispatch( Zend_Controller_Request_Abstract $request ){
$langs = array('en','es','pt-br','de','fr');
$controller = $this->getRequest()->getControllerName();
$lang = $this->getRequest()->getParam('lang');
//Zend Local
$zl = new Zend_Locale(Zend_Locale::BROWSER);
// get Front Controller
$view = Zend_Layout::getMvcInstance()->getView();
$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
//Define language by default
if( $lang == ":lang" ){
$lang = 'en';
$this->_response->setRedirect("/$lang");
}else{
if( !in_array($lang, $langs) ){
$url = "/en/$lang/";
$this->_response->setRedirect( $url );
$lang = 'en';
}
}
$this->setLanguange($lang);
}
public function setLanguange( $lang ){
//Country Code for display local contact info
$ip = "189.204.37.131"; //$_SERVER['SERVER_NAME'] == 'hr' ? '189.204.37.131' : $_SERVER['REMOTE_ADDR'];
$client = new Zend_Http_Client('http://freegeoip.appspot.com/json/'.$ip);
$response = $client->request(Zend_Http_Client::GET)->getBody();
$response = Zend_Json::decode($response, Zend_Json::TYPE_OBJECT);
$country = $response->countrycode;
$cname = strtolower($response->countryname);
$view->CountryData = $response;
switch( $lang ){
case 'en':
$source = 'en_us';
break;
case 'es':
$source = 'es_mx';
break;
}
/////////////////////////////////////////////////////
//----- Try to open csv file --- //
try {
@$translate = new Zend_Translate('csv', APPLICATION_PATH . '/languages/'. $source . '/static.csv' , $lang);
@Zend_Registry::set('Zend_Translate', $translate);
} catch (Exception $e) {
@$translate = new Zend_Translate('csv', APPLICATION_PATH . '/languages/en_us/static.csv' , $lang);
@Zend_Registry::set('Zend_Translate', $translate);
}
}
}