Magento Forum

   
Figuring out localization [Solved]
 
Algiasa
Jr. Member
 
Total Posts:  12
Joined:  2009-01-19
 

This is the kind of problem that I’m sure has been answered somewhere, but I’ve only been able to find bits and pieces here and there. What I’m trying to figure out is how exactly the translation function of a helper works and specifically how to add my own CSV file to magento so it’ll be used by a custom module.

I understand that something like Mage::helper(’paygate’)->__(’sometext’); will look in (presumably) app/locale/[our language]/Mage_Paygate.csv, match ‘sometext’ to the first value of a line and return the second, corresponding text.

What I don’t get is how I can add my own csv and have it be used by my own module. Would the file be MyNamespace_MyModule.csv in /app/locale/[my language]/ ?
How do I use that from my phtml file?
Will I have to modify a helper for this?
And do interfaces/themes enter into the equation somewhere or are they irrelevant?

In fact if there is a wiki\blog post that describes this part of Magento in detail I’d love to have the url; I don’t need to be spoon fed, but some detailed documentation would be nice.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Algiasa
Jr. Member
 
Total Posts:  12
Joined:  2009-01-19
 

Update (and bump):
Some (read a lot) poking around the forum revealed that apparently you can add lines to app/design/frontend/your_interface/your_theme/locale/en_US/translate.csv (for the us locale) and use them with:

$this->__('text I added as a key in translate.csv');
This doesn’t work.
I’ve tried changing values directly in Mage_Payment.csv and using that with
Mage::helper('payment')->__('something')
and it still doesn’t work.
Does anyone have a step-by-step example of how this whole thing works or should I just dump text straight into my phtml file localization be damned?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ryan Sun _Kuafu
Guru
 
Total Posts:  317
Joined:  2008-11-14
FL
 

was also trying to figure out how translator work, after tracing the mage code, got a way to do it
step by step:
1. add translation node to ur config.xml under target module
eg:
<frontend>
<translate>
<modules>
<YourComp_YourModule>
<files>
<default>YourComp_YourModule.csv</default>
</files>
</YourComp_YourModule>
</modules>
</translate>
</frontend>
2. add translation YourComp_YourModule.csv file(follow the format of existing translation csv file ) under locale/en (and other language folders if any)
3. use helper function to get translated strings
Mage::Helper(’yourmodule’)->__(’target string’)

 
Magento Community Magento Community
Magento Community
Magento Community
 
Algiasa
Jr. Member
 
Total Posts:  12
Joined:  2009-01-19
 

Thanks, but this doesn’t seem to work for me… Mage::helper(’module’) returns an error because it tries to find ‘module’ in the Mage namespace (see my post here). I’ve fixed this by declaring my own helper class by adding this to my config.xml

<helpers>
     <
module>
          <class>
Namespace_Module_Helper</class>
      </
module>
</
helpers>
under config->global and using my own helper class (app/code/local/Namespace/Module/Helper/Data.php).
This class simply contains
class Namespace_Module_Helper_Data extends Mage_Core_Helper_Abstract{
}

This got Mage::helper(’module’) working and it now returns an object of my helper class (which essentially is Mage_Core_Helper_Abstract).

I tracked down the __() function all the way to a method called getTranslatedString() in Mage_Core_Model_Translate and all this seems to do is return the string I provided as is. It has other cases where it’s supposed to get the appropriate value from a private array (which is populated god knows where), but it never seems to use these, even when loading the core.

Does anyone fully understand where/how magento uses the language csv files?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Algiasa
Jr. Member
 
Total Posts:  12
Joined:  2009-01-19
 

Well… I think I’ve figured it out. I tried the above solution on another installation and it works. This installation is a 1.1.x version on a linux box with an extra language installed. The one where this doesn’t work is a 1.2.x installation on a windows machine with english only.
I don’t know why this is happening but I’m setting this topic as solved.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MI
Sr. Member
 
Total Posts:  172
Joined:  2008-12-11
Spain
 

Thanks so much!

Now I have things more clear… but still I have one more doubt about translator function “__()”

I have:
Mage::helper(’actualidad’)->__(’Title’)
Mage::helper(’actualidad’)->__(’Status’)

and I need translate the texts “Title” and “Status” to spanish. So I have created a new file Mage_Actualidad.csv. The problem is that I see the translated text “Title” but I can’t translate “Status”
why?? I don´t understand. They are similar.

Is it possible that the text “Status” appears in other csv file with greater priority and so I must translate that other file?

(sorry for my poor english)

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Manos Dilaverakis
Member
 
Total Posts:  49
Joined:  2009-02-25
 

It might help if you post your module config.xml and tell us where exactly your csv file is.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MI
Sr. Member
 
Total Posts:  172
Joined:  2008-12-11
Spain
 

Thanks Manos Dilaverakis!!

My module is “actualidad” is in the folder: app\code\local\Mage\Actualidad
I have posted my config.xml

My csv file is: app\locale\es_ES\Mage_Actualidad.csv

Is all right?? I don’t know what is the problem. :-( :-(

File Attachments
config.xml  (File Size: 4KB - Downloads: 318)
 
Magento Community Magento Community
Magento Community
Magento Community
 
Manos Dilaverakis
Member
 
Total Posts:  49
Joined:  2009-02-25
 

Your config.xml looks ok… you csv is where it should be… weird. Unless someone else can help you might want to experiment a bit. Try other words. Find “status” in the default csv files and change the translation to see if that’s where you’re getting it from…

 
Magento Community Magento Community
Magento Community
Magento Community
 
MI
Sr. Member
 
Total Posts:  172
Joined:  2008-12-11
Spain
 

Thanks again!

Is there any default csv file?? Where is it? Which is it?
How does magento work? Does Magento search the words in the default csv file first and then in the specific file?

 
Magento Community Magento Community
Magento Community
Magento Community
 
MattKern
Jr. Member
 
Total Posts:  4
Joined:  2007-09-02
 

I have to add my solution since it seems there is no clear cut easy one - at least not one I could find.

the file to edit for english
app/locale/en_US/Mage_Catalog.csv ( I picked this one because it seemed generic enough )

add your lines to the .csv file

“Home","This is the Home Page Button”

then in your .phtml file

<?php echo Mage::helper('catalog')->__('Home') ?>

this will echo

This is the Home Page Button

Im just sorry it took hours to figure out a relatively simple thing that should be well documented somewhere.

hope that helps someone.

 
Magento Community Magento Community
Magento Community
Magento Community
 
crescentits
Jr. Member
 
Avatar
Total Posts:  2
Joined:  2012-03-27
 

Hi

Thanks for all I got very valuable information from this blog. Thanks Sharing information to all.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top