Skip to content

Commit

Permalink
Show Tibet as part of China on map (#11930)
Browse files Browse the repository at this point in the history
* Revert "free tibet!"

This reverts commit 4e47c8a.

* Remove unneeded translations

* adjust API

* fix tests

* update screenshots

* update tests files

* update screenshot

* Do not change detected location

* update tests

* Fix continent detection for old records

* submodule update

* update screenshots

* Cleanup

* use group by filters only if needed

* make filter work for datatable maps
  • Loading branch information
sgiehl committed Sep 12, 2017
1 parent 571d96e commit 3cb7169
Show file tree
Hide file tree
Showing 61 changed files with 178 additions and 247 deletions.
4 changes: 4 additions & 0 deletions core/Common.php
Expand Up @@ -1026,6 +1026,10 @@ public static function getContinent($country)

$countryList = $dataProvider->getCountryList();

if ($country == 'ti') {
$country = 'cn';
}

return isset($countryList[$country]) ? $countryList[$country] : 'unk';
}

Expand Down
1 change: 0 additions & 1 deletion core/Intl/Data/Resources/countries.php
Expand Up @@ -237,7 +237,6 @@
'tf' => 'ant',
'tg' => 'afr',
'th' => 'asi',
'ti' => 'asi', // Tibet (no iso 3166 code)
'tj' => 'asi',
'tk' => 'oce',
'tl' => 'asi',
Expand Down
2 changes: 1 addition & 1 deletion core/Intl/Data/Resources/languages-to-countries.php
Expand Up @@ -54,7 +54,7 @@
'sr' => 'rs', // Serbian => Serbia
'sv' => 'se', // Swedish => Sweden
'th' => 'th', // Thai => Thailand
'bo' => 'ti', // Tibetan => Tibet
'bo' => 'cn', // Tibetan => China
'tr' => 'tr', // Turkish => Turkey
'uk' => 'ua', // Ukrainian => Ukraine
);
1 change: 0 additions & 1 deletion plugins/MobileMessaging/CountryCallingCodes.php
Expand Up @@ -234,7 +234,6 @@ class CountryCallingCodes
// 'tf' => 'MISSING CODE',
'tg' => '228',
'th' => '66',
// 'ti' => 'MISSING CODE',
'tj' => '992',
'tk' => '690',
'tl' => '670',
Expand Down
2 changes: 1 addition & 1 deletion plugins/Morpheus/icons
Submodule icons updated from 0c4e30 to 3d383b
41 changes: 41 additions & 0 deletions plugins/UserCountry/API.php
Expand Up @@ -32,6 +32,26 @@ public function getCountry($idSite, $period, $date, $segment = false)
{
$dataTable = $this->getDataTable(Archiver::COUNTRY_RECORD_NAME, $idSite, $period, $date, $segment);

$dataTables = [$dataTable];

if ($dataTable instanceof DataTable\Map) {
$dataTables = $dataTable->getDataTables();
}

foreach ($dataTables as $dt) {
if ($dt->getRowFromLabel('ti')) {
$dt->filter('GroupBy', array(
'label',
function ($label) {
if ($label == 'ti') {
return 'cn';
}
return $label;
}
));
}
}

// apply filter on the whole datatable in order the inline search to work (searches are done on "beautiful" label)
$dataTable->filter('AddSegmentValue');
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'code'));
Expand Down Expand Up @@ -75,6 +95,27 @@ public function getRegion($idSite, $period, $date, $segment = false)
$separator = Archiver::LOCATION_SEPARATOR;
$unk = Visit::UNKNOWN_CODE;

// show visits tracked as Tibet as region of China
$dataTables = [$dataTable];

if ($dataTable instanceof DataTable\Map) {
$dataTables = $dataTable->getDataTables();
}

foreach ($dataTables as $dt) {
if ($dt->getRowFromLabel('1|ti')) {
$dt->filter('GroupBy', array(
'label',
function ($label) {
if ($label == '1|ti') {
return 'cn';
}
return $label;
}
));
}
}

// split the label and put the elements into the 'region' and 'country' metadata fields
$dataTable->filter('ColumnCallbackAddMetadata',
array('label', 'region', __NAMESPACE__ . '\getElementFromStringArray', array($separator, 0, $unk)));
Expand Down
22 changes: 6 additions & 16 deletions plugins/UserCountry/LocationProvider/GeoIp.php
Expand Up @@ -54,7 +54,6 @@ abstract class GeoIp extends LocationProvider
*/
public function completeLocationResult(&$location)
{
$this->fixupLocation($location);
parent::completeLocationResult($location);

// set region name if region code is set
Expand All @@ -68,21 +67,6 @@ public function completeLocationResult(&$location)
}
}

/**
* Fix up data to work with our SVG maps which include 'Tib' boundaries
*/
protected function fixupLocation(&$location)
{
if (!empty($location[self::REGION_CODE_KEY])
&& $location[self::REGION_CODE_KEY] == '14'
&& !empty($location[self::COUNTRY_CODE_KEY])
&& strtoupper($location[self::COUNTRY_CODE_KEY]) == 'CN'
) {
$location[self::COUNTRY_CODE_KEY] = 'ti';
$location[self::REGION_CODE_KEY] = '1';
}
}

/**
* Returns true if this provider has been setup correctly, the error message if
* otherwise.
Expand Down Expand Up @@ -155,6 +139,12 @@ public static function getRegionNameFromCodes($countryCode, $regionCode)
$countryCode = strtoupper($countryCode);
$regionCode = strtoupper($regionCode);

// ensure tibet is shown as region of china
if ($countryCode == 'TI' && $regionCode == '1') {
$regionCode = '14';
$countryCode = 'CN';
}

if (isset($regionNames[$countryCode][$regionCode])) {
return $regionNames[$countryCode][$regionCode];
} else {
Expand Down
8 changes: 8 additions & 0 deletions plugins/UserCountry/functions.php
Expand Up @@ -22,6 +22,10 @@
*/
function getFlagFromCode($code)
{
if (strtolower($code) == 'ti') {
$code = 'cn';
}

$pathInPiwik = 'plugins/Morpheus/icons/dist/flags/%s.png';
$pathWithCode = sprintf($pathInPiwik, $code);
$absolutePath = PIWIK_INCLUDE_PATH . '/' . $pathWithCode;
Expand Down Expand Up @@ -57,6 +61,10 @@ function countryTranslate($label)
return Piwik::translate('General_Unknown');
}

if (strtolower($label) == 'ti') {
$label = 'cn';
}

// Try to get name from Intl plugin
$key = 'Intl_Country_' . strtoupper($label);
$country = Piwik::translate($key);
Expand Down
5 changes: 0 additions & 5 deletions plugins/UserCountry/lang/cs.json
Expand Up @@ -16,7 +16,6 @@
"country_a2": "Satelitní poskytovatel",
"country_cat": "Katalánsky mluvící země",
"country_o1": "ostatní země",
"country_ti": "Tibet",
"CurrentLocationIntro": "Podle tohoto poskytovatele je vaše aktuální umístění",
"DefaultLocationProviderDesc1": "Výchozí poskytovatel umístění odhaduje zemi návštěvníka na základě použitého jazyka.",
"DefaultLocationProviderDesc2": "To není příliš přesné, proto doporučujeme %1$sinstalovat a používat %2$sGEOIP%3$s.%4$s",
Expand Down Expand Up @@ -94,8 +93,4 @@
"UpdaterWasLastRun": "Aktualizátor byl naposledy spuštěn v %s.",
"UpdaterWillRunNext": "Další spuštění je naplánováno na %s.",
"WidgetLocation": "Umístění návštěvníka"
},
"Intl": {
"Country_TI": "Tibet"
}
}
4 changes: 0 additions & 4 deletions plugins/UserCountry/lang/da.json
Expand Up @@ -16,7 +16,6 @@
"country_a2": "Satellit udbyder",
"country_cat": "Catalansk-talende samfund",
"country_o1": "Andet land",
"country_ti": "Tibet",
"CurrentLocationIntro": "I følge denne tjeneste er din aktuelle lokation",
"DefaultLocationProviderDesc1": "Standardlokationstjenesten gætter en besøgendes land baseret på det sprog de bruger.",
"DefaultLocationProviderDesc2": "Dette er ikke særlig nøjagtigt, så %1$svi anbefaler at du installerer og bruger %2$sGeoIP%3$s.%4$s",
Expand Down Expand Up @@ -94,8 +93,5 @@
"UpdaterWasLastRun": "Opdateringen blev sidst blev kørt den %s.",
"UpdaterWillRunNext": "Næste planlagte kørsel %s.",
"WidgetLocation": "Besøgendes lokation"
},
"Intl": {
"Country_TI": "Tibet"
}
}
4 changes: 0 additions & 4 deletions plugins/UserCountry/lang/de.json
Expand Up @@ -16,7 +16,6 @@
"country_a2": "Satelliten-Anbieter",
"country_cat": "Katalanisch sprechende Gemeinden",
"country_o1": "Anderes Land",
"country_ti": "Tibet",
"CurrentLocationIntro": "Gemäß diesem Provider ist Ihr derzeitiger Standort",
"DefaultLocationProviderDesc1": "Die voreingestellte Standorterkennung versucht das Herkunftsland des Besuchers anhand dessen verwendeter Sprache zu erkennen.",
"DefaultLocationProviderDesc2": "Dies ist nicht sehr genau, daher %1$swird empfohlen %2$sGeoIP%3$s zu installieren und zu nutzen.%4$s",
Expand Down Expand Up @@ -94,8 +93,5 @@
"UpdaterWasLastRun": "Die Aktualisierung wurde zuletzt ausgeführt am %s.",
"UpdaterWillRunNext": "Nächste Ausführung geplant für %s.",
"WidgetLocation": "Besucherstandort"
},
"Intl": {
"Country_TI": "Tibet"
}
}
4 changes: 0 additions & 4 deletions plugins/UserCountry/lang/el.json
Expand Up @@ -16,7 +16,6 @@
"country_a2": "Πάροχος δορυφόρου",
"country_cat": "Καταλανικόφωνες κοινότητες",
"country_o1": "Άλλη Χώρα",
"country_ti": "Θιβέτ",
"CurrentLocationIntro": "Σύμφωνα με τον πάροχο, η τρέχουσα τοποθεσία σας είναι",
"DefaultLocationProviderDesc1": "Ο προεπιλεγμένος πάροχος θέσης εικάζει τη χώρα του επισκέπτη με βάση τη γλώσσα που χρησιμοποιεί.",
"DefaultLocationProviderDesc2": "Αυτό δεν είναι πολύ ακριβές, έτσι %1$sπροτείνουμε την εγκατάσταση και τη χρήση %2$sGeoIP%3$s.%4$s",
Expand Down Expand Up @@ -94,8 +93,5 @@
"UpdaterWasLastRun": "Το πρόγραμμα ενημέρωσης εκτελέστηκε τελευταία στις %s.",
"UpdaterWillRunNext": "Είναι προγραμματισμένο για εκτέλεση στις %s.",
"WidgetLocation": "Τοποθεσία Επισκέπτη"
},
"Intl": {
"Country_TI": "Θιβέτ"
}
}
4 changes: 0 additions & 4 deletions plugins/UserCountry/lang/en.json
Expand Up @@ -16,7 +16,6 @@
"country_a2": "Satellite Provider",
"country_cat": "Catalan-speaking communities",
"country_o1": "Other Country",
"country_ti": "Tibet",
"CurrentLocationIntro": "According to this provider, your current location is",
"DefaultLocationProviderDesc1": "The default location provider guesses a visitor's country based on the language they use.",
"DefaultLocationProviderDesc2": "This is not very accurate, so %1$swe recommend installing and using %2$sGeoIP%3$s.%4$s",
Expand Down Expand Up @@ -94,8 +93,5 @@
"UpdaterWasLastRun": "The updater was last run on %s.",
"UpdaterWillRunNext": "It is next scheduled to run on %s.",
"WidgetLocation": "Visitor Location"
},
"Intl": {
"Country_TI": "Tibet"
}
}
4 changes: 0 additions & 4 deletions plugins/UserCountry/lang/es.json
Expand Up @@ -16,7 +16,6 @@
"country_a2": "Proveedor Satelital",
"country_cat": "Comunidades de habla catalana",
"country_o1": "Otro país",
"country_ti": "Tibet",
"CurrentLocationIntro": "De acuerdo a este proveedor, su actual ubicación es",
"DefaultLocationProviderDesc1": "La ubicación predeterminada del proveedor asume que el país del visitante es por el lenguaje que el mismo utiliza.",
"DefaultLocationProviderDesc2": "No es muy preciso, por lo tanto %1$srecomendamos instalar y utilizar %2$sGeoIP%3$s.%4$s",
Expand Down Expand Up @@ -94,8 +93,5 @@
"UpdaterWasLastRun": "El actualizador se ejecutó por última vez en %s.",
"UpdaterWillRunNext": "Está programada la ejecución para el %s.",
"WidgetLocation": "Ubicación del visitante"
},
"Intl": {
"Country_TI": "Tíbet"
}
}
4 changes: 0 additions & 4 deletions plugins/UserCountry/lang/et.json
Expand Up @@ -8,7 +8,6 @@
"country_a2": "Satelliidi pakkuja",
"country_cat": "Katalaani kommuunid",
"country_o1": "Muu riik",
"country_ti": "Tiibet",
"CurrentLocationIntro": "Antud pakkuja andmete alusel on sinu praegune asukoht",
"DistinctCountries": "%s eri riigist",
"DownloadingDb": "Laen alla %s",
Expand All @@ -31,8 +30,5 @@
"SubmenuLocations": "Asukohad",
"UpdaterWasLastRun": "Uuendaja käivitus viimati %s.",
"WidgetLocation": "Külastajate asukohad"
},
"Intl": {
"Country_TI": "Tiibet"
}
}
1 change: 0 additions & 1 deletion plugins/UserCountry/lang/fi.json
Expand Up @@ -16,7 +16,6 @@
"country_a2": "Satelliittiyhteys",
"country_cat": "Katalaania puhuvat alueet",
"country_o1": "Muu maa",
"country_ti": "Tiibet",
"CurrentLocationIntro": "Tämän toteutuksen mukaan nykyinen sijaintisi on",
"DefaultLocationProviderDesc1": "Oletustoteutus arvaa käyttäjien maan kielen perusteella.",
"DefaultLocationProviderDesc2": "Tämä ei ole erityisen tarkkaa, joten %1$ssuosittelemme asentamaan ja käyttämään %2$sGeoIp:tä%3$s.%4$s",
Expand Down
4 changes: 0 additions & 4 deletions plugins/UserCountry/lang/fr.json
Expand Up @@ -16,7 +16,6 @@
"country_a2": "Fournisseur satellite",
"country_cat": "Communautés de langue Catalane",
"country_o1": "Autre pays",
"country_ti": "Tibet",
"CurrentLocationIntro": "D'après ce fournisseur, votre emplacement actuel est",
"DefaultLocationProviderDesc1": "Le fournisseur de localisation par défaut devine le pays d'un visiteur en se basant sur le langage de son navigateur.",
"DefaultLocationProviderDesc2": "Ce n'est pas très précis, nous recommandons donc %1$sd'installer et d'utiliser %2$sGeoIP%3$s.%4$s",
Expand Down Expand Up @@ -94,8 +93,5 @@
"UpdaterWasLastRun": "La dernière mise à jour a été effectuée le %s.",
"UpdaterWillRunNext": "Est planifié pour s'exécuter le %s.",
"WidgetLocation": "Emplacement du visiteur"
},
"Intl": {
"Country_TI": "Tibet"
}
}
1 change: 0 additions & 1 deletion plugins/UserCountry/lang/gl.json
Expand Up @@ -3,7 +3,6 @@
"Continent": "Continente",
"Country": "País",
"country_o1": "Outro país",
"country_ti": "Tíbet",
"DistinctCountries": "%s continentes distintos",
"DownloadingDb": "A descargar %s",
"DownloadNewDatabasesEvery": "Actualizar as bases de datos cada",
Expand Down
1 change: 0 additions & 1 deletion plugins/UserCountry/lang/hi.json
Expand Up @@ -15,7 +15,6 @@
"country_a2": "सैटेलाइट प्रदाता",
"country_cat": "कैटलन भाषी समुदायों",
"country_o1": "अन्य देश",
"country_ti": "तिब्बत",
"CurrentLocationIntro": "इस प्रदाता के अनुसार, आपका वर्तमान स्थान है",
"DefaultLocationProviderDesc1": "एक आगंतुक का देश डिफ़ॉल्ट स्थान प्रदाता के अनुमान का इस्तेमाल वे भाषा के आधार पर करते है.",
"DefaultLocationProviderDesc2": "यह बहुत सही नहीं है, तो %1$sहम स्थापित करने और %2$sGeoIP%3$s का उपयोग करना चाहिये.%4$s",
Expand Down
4 changes: 0 additions & 4 deletions plugins/UserCountry/lang/id.json
Expand Up @@ -16,7 +16,6 @@
"country_a2": "Penyedia Satelit",
"country_cat": "Masyarakat berbahasa Katalan",
"country_o1": "Negara Lain",
"country_ti": "Tibet",
"CurrentLocationIntro": "Berdasar penyedia ini, lokasi Anda adalah",
"DefaultLocationProviderDesc1": "Lokasi penyedia asali menebak negara pengunjung dari bahasa yang digunakan.",
"DefaultLocationProviderDesc2": "Ini sangat tidak teliti, serta %1$skami menyarankan memasang dan menggunakan %2$sGeoIP%3$s.%4$s",
Expand Down Expand Up @@ -87,8 +86,5 @@
"UpdaterHasNotBeenRun": "Pembaruan belum pernah berjalan.",
"UpdaterWasLastRun": "Pembaruan terakhir berjalan dalam %s.",
"WidgetLocation": "Lokasi Pengunjung"
},
"Intl": {
"Country_TI": "Tibet"
}
}
4 changes: 0 additions & 4 deletions plugins/UserCountry/lang/it.json
Expand Up @@ -16,7 +16,6 @@
"country_a2": "Satellite Provider",
"country_cat": "Comunità che parlano catalano",
"country_o1": "Altri Paesi",
"country_ti": "Tibet",
"CurrentLocationIntro": "In base a questo provider, la tua posizione attuale è",
"DefaultLocationProviderDesc1": "L'individuatore di posizione predefinito desume il paese di un visitatore dalla lingua utilizzata.",
"DefaultLocationProviderDesc2": "Quasta non è molto accurata, dunque %1$snoi raccomandiamo di installare e utilizzare %2$sGeoIP%3$s.%4$s",
Expand Down Expand Up @@ -94,8 +93,5 @@
"UpdaterWasLastRun": "Il programma di aggiornamento è stato eseguito per l'ultima volta il %s.",
"UpdaterWillRunNext": "È programmato per essere eseguito il %s.",
"WidgetLocation": "Posizione Visitatore"
},
"Intl": {
"Country_TI": "Tibet"
}
}
4 changes: 0 additions & 4 deletions plugins/UserCountry/lang/ja.json
Expand Up @@ -16,7 +16,6 @@
"country_a2": "衛星プロバイダ",
"country_cat": "カタロニア語圏のコミュニティ",
"country_o1": "その他の国",
"country_ti": "チベット",
"CurrentLocationIntro": "このプロバイダーによると、あなたの現在地は",
"DefaultLocationProviderDesc1": "デフォルトロケーションプロバイダーでは、ビジターの国は使用言語に基づいて推測されます。",
"DefaultLocationProviderDesc2": "精度が低いため、%1$s%2$sGeoIP%3$sのインストールと使用をお勧めします。%4$s",
Expand Down Expand Up @@ -94,8 +93,5 @@
"UpdaterWasLastRun": "アップデーターは、%s の最後に実行されました。",
"UpdaterWillRunNext": "それは次に %s で実行されるようスケジュールされています。",
"WidgetLocation": "ビジターの位置"
},
"Intl": {
"Country_TI": "チベット"
}
}
4 changes: 0 additions & 4 deletions plugins/UserCountry/lang/ko.json
Expand Up @@ -16,7 +16,6 @@
"country_a2": "위성 공급자",
"country_cat": "카탈로니아 지역의 커뮤니티",
"country_o1": "기타 국가",
"country_ti": "티베트",
"CurrentLocationIntro": "이 공급자에 따르면, 현재 위치는",
"DefaultLocationProviderDesc1": "방문자의 국가에 기반하는 언어에서 추측하는 기본 위치 공급자입니다.",
"DefaultLocationProviderDesc2": "이것은 매우 부정확합니다. 그래서 %1$s우리는 %2$sGeoIP%3$s를 설치하여 사용하는 것을 추천합니다.%4$s",
Expand Down Expand Up @@ -94,8 +93,5 @@
"UpdaterWasLastRun": "%s에 마지막 업데이트 확인",
"UpdaterWillRunNext": "%s에 실행이 계획되어 있습니다.",
"WidgetLocation": "방문자 위치"
},
"Intl": {
"Country_TI": "티베트"
}
}

0 comments on commit 3cb7169

Please sign in to comment.