File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed
Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change 44
55use PharData ;
66use Exception ;
7+ use GeoIp2 \Model \City ;
78use GeoIp2 \Database \Reader ;
9+ use Illuminate \Support \Arr ;
810
911class MaxMindDatabase extends AbstractService
1012{
@@ -55,6 +57,7 @@ public function locate($ip)
5557 'lon ' => $ record ->location ->longitude ,
5658 'timezone ' => $ record ->location ->timeZone ,
5759 'continent ' => $ record ->continent ->code ,
60+ 'localizations ' => $ this ->getLocalizations ($ record ),
5861 ]);
5962 }
6063
@@ -166,4 +169,23 @@ protected function deleteDirectory(string $directory)
166169
167170 return rmdir ($ directory );
168171 }
172+
173+ /**
174+ * Get localized country name, state name and city name based on config languages
175+ *
176+ * @param City $record
177+ * @return array
178+ */
179+ private function getLocalizations (City $ record ): array
180+ {
181+ $ localizations = [];
182+
183+ foreach ($ this ->config ('locales ' , ['en ' ]) as $ lang ) {
184+ $ localizations [$ lang ]['country ' ] = Arr::get ($ record ->country ->names , $ lang );
185+ $ localizations [$ lang ]['state_name ' ] = Arr::get ($ record ->mostSpecificSubdivision ->names , $ lang );
186+ $ localizations [$ lang ]['city ' ] = Arr::get ($ record ->city ->names , $ lang );
187+ }
188+
189+ return $ localizations ;
190+ }
169191}
Original file line number Diff line number Diff line change 22
33namespace Torann \GeoIP \Services ;
44
5+ use GeoIp2 \Model \City ;
6+ use Illuminate \Support \Arr ;
57use GeoIp2 \WebService \Client ;
68
79class MaxMindWebService extends AbstractService
@@ -46,6 +48,27 @@ public function locate($ip)
4648 'lon ' => $ record ->location ->longitude ,
4749 'timezone ' => $ record ->location ->timeZone ,
4850 'continent ' => $ record ->continent ->code ,
51+ 'localizations ' => $ this ->getLocalizations ($ record ),
4952 ]);
5053 }
51- }
54+
55+ /**
56+ * Get localized country name, state name and city name based on config languages
57+ *
58+ * @param City $record
59+ *
60+ * @return array
61+ */
62+ private function getLocalizations (City $ record ): array
63+ {
64+ $ localizations = [];
65+
66+ foreach ($ this ->config ('locales ' , ['en ' ]) as $ lang ) {
67+ $ localizations [$ lang ]['country ' ] = Arr::get ($ record ->country ->names , $ lang );
68+ $ localizations [$ lang ]['state_name ' ] = Arr::get ($ record ->mostSpecificSubdivision ->names , $ lang );
69+ $ localizations [$ lang ]['city ' ] = Arr::get ($ record ->city ->names , $ lang );
70+ }
71+
72+ return $ localizations ;
73+ }
74+ }
You can’t perform that action at this time.
0 commit comments