Introducing php-swiss-cantons
This article has been published a while ago.
If this is a technical article some information might be out of date. If something is terribly broken, let me know and I will update the article accordingly.
A month ago I released a simple PHP-Package called php-swiss-cantons
. As the name suggests it’s about the 26 Swiss cantons.
At work, I’m responsible for some projects which are optimized for Google Adwords and in particular for location-based search terms.
For example, you’re searching Google for pet shelter in Zurich
. You would click on the ad of our imaginary pet shelter website and the term zurich
or zh
would be passed to the website.
Now we would like to adapt images and texts on the page to your search term. Sounds easy right? Well, the easy part is to change images based on the location string. But it it’s much more complicated when you're dealing with text in 2 to 3 languages. [email protected]
is the first step to manage this behaviour in a single package.
Version 1.0 is currently a nice abstracted API to search through arrays. Here’s a simple example:
Get the Canton by its abbreviation
$cantonManager = new Wnx\SwissCantons\CantonManager();
$canton = $cantonManager->getByAppreviation('GR');
echo $canton->setLanguage('de')->getName(); // Graubünden
Get the Canton by it’s official name in one of four languages
$cantonManager = new Wnx\SwissCantons\CantonManager();
$canton = $cantonManager->getByName('Graubünden');
echo $canton->getAbbreviation(); // GR
The next version will include more language-based information like the different cases a Canton can be used aka „Der Kasus“. I’m not sure how I could structure this information, but I hope I can release an updated version in the upcoming weeks/months.
You find more information about the package on GitHub.