问题
I have spent hours searching to find where magento stores full county name. We can get a full list of countries using this code:
$_countries = Mage::getResourceModel('directory/country_collection')
->loadData()
->toOptionArray(false);
This will return an array with country code and name, I investigated the directory module, and found out this call gets data from the table
directory_county
But this table don't have full county name! So where is it stored? and how is it retrieved using that call?
Thanks in advance.
回答1:
Ok so to compensate for my wrong answer. Here is how this works:
/lib/Zend/Locale/Data/en.xml - if your store is in english, else another xml in the same directoery is read. Every country is there and its code under the xml tag
<territory>
The xml is cached using the Zend_Cache_Core class.
/lib/Zend/Locale.php - function getTranslation invokes the lib/Zend/Cache/Core.php class to load from the cache.
Example: If you change the name of some country in en.xml and clear the magento cache. You will see the change when u invoke your code again.
回答2:
Full country names are not stored in database. Magento uses inbuilt Zend functionality.
Check file: lib/Zend/Locale/Data/Translation.php
for full list.
回答3:
Use the Zend_Local translation.
<?php
$code = 'EN';
echo Mage::app()->getLocale()->getTranslation($code, 'Territory', null, 2);
?>
Use the column 'iso2_code' from the table 'directory_country' for your $code.
回答4:
Magneto only stores country codes in DB, and relies for names on Zend's Locale module to provide translated names, for different locale.
By the toOptionArray
method it invokes the Zend_Locale
class to get the translated value.
Refer $name = Mage::app()->getLocale()->getCountryTranslation($data['value']);
, which gets to Mage_Core_Model_Locale
and then to Zend_Locale
.
It decides which of the node from the data to read, by the switch case statement in Zend_Locale_Data::getContent()
line# 962, 963
Magento caches the names, so if you make any change to XML
files, make sure to clean your cache folder to get what you seek.
来源:https://stackoverflow.com/questions/24932715/where-magento-stores-country-full-name