When looking through the multistore language selector (in our theme) we see that the dropdown is populated as follows:
foreach ($this->getStores() as $_lang) {
$select_stores[] = '<option '.$_selected_option.' value="'. $_lang->getCurrentUrl() .'">'. $this->htmlEscape($_lang->getName()) .'</option>';
}
The problem is that the (real) language is not the store name we give it and is fetched through '$_lang->getName()'
But rather the Locale set in the backend in storeconfig
$_language_code = substr(Mage::getStoreConfig('general/locale/code', $_lang->getId()),0,2);
I know how to fetch ths ID, but ….
Question: How can we now fetch the Locale full language name to populate the dropdown? (so German or Deutsch for Germany and English or Engels for English)
(And maybe cut off the the piece between brackets, so English (United States) becomes English)
Best Answer
Here is possible solution. Not the most elegant but it should work.
First you should get all the languages that appear in the backend in the locale config section.
This will get you an array like this:
You can get the current locale code like you already do
Now all you have to do is to loop through all the languages and see if one matches your code.
If you want to lose the country name just do this.
Or you can use a regex that seams cleaner.
Of course you should wrap all this code in a method and just use that method.
[EDIT]
An other approach would be to get all the languages based on the language code only:
this should return something like
Then you have to get the lang code like this (you already do that):
And just check
This seams cleaner but I'm not sure if it works correctly for all the values.
The first method seams safer because it uses the same options that you see in the backend.
Give either one of them a try.
[EDIT] Example of the final code from the question author (works like a charm)