Extract translation phrases from Magento - php

I'm relatively new to Magento and working on a site build for a client and they simply need a list of phrases used throughout the site to be sent to a translator. I'm a little surprised that there isn't something simple and built into Magento for easily pulling this stuff out, which is why I'm writing here now. Is there a relatively simple way to extract translation phrases from a Magento app? Something built in that might not be obvious (to me)? or some useful library out there? This includes everything used in the templates (or controllers) like so:
$this->__("Some phrase on my website...");
... as well as cases in the layout XML where the 'translate' attribute is set, etc.
And taking this one step further, I'm aware of the available translations available from Magento here: http://www.magentocommerce.com/translations -- is there something simple to make sure I'm not double-doing it for phrases that might already exist in these packs?
And further still, is there a something to pull all translatables out of the database?
And if the answer for all this turns out to be 'no', I need to be very thorough with this so any advice on pitfalls or particular spots I need to be aware of where I might not think of pulling translations from, how you might have achieved something like this before, etc. -- I would love to hear your tips. Thanks!

I know I'm late, but anyway, I’ve just uploaded an extension that does that: Language CSV Files Generator.
It only extracts strings from .php and .phtml files, I have no idea of how to get the .xml ones. Hope that someone out there could share some idea.
hope you like it

Take a look in /app/locale/(language_country)/*.csv files.

There are different solutions to get the strings from CSV files of Magento:
check the links The Ultimate Guide to Translating Magento (using Translation Memory software)
and How to translate Magento using OmegaT software

Related

Using PHP, how can I identify, (decompress if applicable), and extract the files from .tar, .gz, .tar.gz, .zip files?

I know that \Phar and \PharData exist, but I'm having some trouble with the methods they supply so far. I'm still having to detect the mime-type / file type by whatever means, before determining which Phar*::method() to use in an attempt to extract the archive and do work on the files it contains.
Is there a go-to, "easy-button" class that I could include (maybe some package available via composer) that handles this at a very high level? Or am I failing to use the Phar and friends properly or in need of re-RTM so far?
Basically, I want to do the following (it's a CLI script that I control for now, so security, while important with this type of thing, is on the backburner for now):
Detect that a file might be an archive of some kind.
Validate that it seems to be one of the following: .tar, .gz, .tar.gz, or .zip.
If so, attempt to extract the archive and then parse the content of it's actual files.
Is there an "easy-button" for this that I'm unaware of, or do I need to build some logic that guesses as best it can as to what type of archive it might be, and then try to use the appropriate Phar* method to attempt to extract it's files and do whatever work I need to on them?
I hope that makes sense the way I wrote it. I'm trying to avoid re-inventing the wheel for a mini-project here if someone has already figured all of this out basically.
So, while continuing to research this I ended up seeing my own (this) SO question in google search results, which annoys me for some reason. So just in case someone stumbles upon this looking for a good solution, I've since found a couple by searching https://packagist.org/search/?q=archive (go figure):
Here's a few of them that seem promising.
wapmorgan/UnifiedArchive:
wapmorgan/UnifiedArchive (packagist)
wapmorgan/UnifiedArchive (github source)
Features (at first glance):
Only has one requirement of pear/archive_tar (which includes a few
more utility classes also from pear).
It attempts to detect the filetype for you, so it could eliminate the need to do that on your own.
alchemy/zippy:
alchemy/zippy (packagist)
alchemy-fr/Zippy (github source)
Features (at first glance):
Code looks to have been very well designed.
Seems to integrate with Laravel and guzzle\guzzle (the popular php http client) in some way so that might be an advantage for some.
zetacomponents/Archive
zetacomponents/Archive (packagist)
zetacomponents/Archive (github source)
Features (at first glance):
It seems to be a pure php implementation? If so that's just awesome.
Last updated 15 days ago, so it's the most active of the three I mentioned.
Seems to be maintained by an organization as opposed to a single person.
It has the most downloads by far on packagist (when searching for "archive"), and though I haven't played with it yet, that's usually a good sign.
Disclaimer: I have only actually tried wapmorgan/UnifiedArchive as of this writing, and so far it's exactly what I was looking for.
Anyway, I hope this helps anyone who might stumble upon this question.
If you don't need pure php and if your code is running on a linux machine, a
exec('uncompress [-cfv] [file...]');
or a
exec('unzip filename.zip -d destination');
will extract the file and make it usable for php.
Of course you need to check the extension (zip, tar, etc) in order to call the right command

Creating an octopress theme from a wordpress theme

Ive been using wordpress for awhile now and wanted to try something different. Enter in my discovery of the world of static website generates. Now I have my eyes on Octopress which I know to be built on jekyll. Before I start getting dirty in ruby I want to know if its relatively possible to translate my current wordpress theme to a static site.
That's exactly what I did recently:
http://eduncan911.com/blog
I copied a friend's Wordpress theme (with permission) of almost the same design:
http://forgetfoo.com
"I want to know if its relatively possible"
To answer your first concern, the answer is a big ol' YES. That's what make Jekyll so good for these kind of things: it's just raw HTML and css and js in a few directories. Place them anywhere you like, and start cutting away at chunks in includes, wrap some plugins, etc and before you know it, you are rake generate and rake deploy.
Octopress makes it even sweeter by having a large number of plugins, a blog-like template system already structured*** (see below), and bunch of defaults all setup for blogging.
The issue with Octopress' theme is as I said above, it is purely setup as a blogging platform. You'd need to highly modify, or in my case just completely ignore, the template they have and just piggy back on the nice Github Pages, SCSS, and plugins it comes with and roll your own html templates. It's really really really easy.
Where do you start?
/source/index.html
You start here with this YAML file. At the top is a definition of layout, which is used to pick what "wrapper" or layout you want to surround this index.html content with. To make a new template, one like yours, I'd call it layout: fuse_homepage. Then go into source/_layouts/ and create a new `fuse_homepage.html'.
Start with your own theme and format as you want
But see, you don't even have to do that. Hell, just paste your entire homepage HTML right
into that source/index.html to start with (make sure to keep the --- YAML markers at the top, but get rid of the layout). Start there and break things out later when you get tired of coping and pasting the header/footers. Heck, just start there - make a fuse_header.html and fuse_footer.html and just share those for now.
Ignore Octopress' theme layout - it's just for hackers that don't do UX and just want to tweak things. Designers or people that like to control their code will want to roll your own.
It really is that flexible. However you want to break it up, you can. Want a new page, just call rake new_page["title"], which all this does is create either an /title.html, or /title/index.html, depending on your settings in the config file. But see, you don't even have to do that. Just create the file yourself - BAM, it is copied on deployment.
Regrets with Octopress
Trying to force the themes to do my bidding, chasing rabbits
I only regret trying to follow the Octopress' author's format - wasted so much time and got so turned off at Octopress. In the end, I just ignored it and did my own. Much easier, and I know where everything is. I also wanted nice and cleanly formatted HTML - a show that I care about my code. The default Octorpess theme and structure invites so many mis-placed tabs and spaces that it's just ugly. Doing your own, you are in full control, space by little space insert.
Importing posts
There's a huge amount of Google links to help you export your WRX from Wordpress, and to generate a the post files automagically. Be prepared to try several different ones as they aren't all perfect.
import comments into Disqus
Unless you are already using Disqus on Wordpress, you are going to have a horrible time with this one.
I can now claim myself to be an WRX/BlogML expert after my nearly 100 tries of importing and exporting and fixing and so on. There is no documentation on either importer (Disqus nor Wordpress) to tell you of the individual required fields. For example, Wordpress requires wp:comment_id to be set, and unique for each and every post you import whereas Disqus requires an wp:comment_email field, even though say it is optional (it's BS, argh).
Be prepared to hack code. It is a hacker's framework after all
Do note though: it is a lot of work to hack around the static site. Doing your own template will save you so much time. You'll also may want to write your own custom plugins, which I did, to get around the bugs in peoples github repos - it's pretty easy, but does require coding.
I spent about a month off and on until I got my new blog/static site to where I liked it for launch. A lot more than I wanted, but it was "fun" learning new languages (Ruby, Python, installed Debian linux in a VM cause Windows just sucks at that stuff).
If you aren't prepared to write that much, there are a couple more static site generators out there as I blogged about (hey, got to show off my Octopress and custom theme!):
http://eduncan911.com/software/the-static-blog-boom.html
Btw, nice site...

Templating different languages in a PHP webapp

I'm writing a webapp in german, so all buttons,text,tooltips etc. are in german for now. But I want to use some kind of template file for the webapp so I can quick change to another language if needed. I thought about textfile that I explode with "\n" and load into a sessionvariable to have always all text the user will need in his session. An other approach would be to parse such a file i.e. a XML document like this:
<?xml version="1.0"?>
<phrase>
<placeholder></placeholder>
<value></value>
</phrase>
where every field has it's own name/value that represents a textsnippet or button or whatever on the website, and then cast it into an object an cache it for everyone. I think the second approach is the best for working with multiple languages for a webapp. Anybody perhaps some pointers what I could do even better, or just post how you did this kind of languagetemplating for mutlinational webpages/webapps in the past.
Since you are looking for a translation solution, I understand you don't use a framework to develop your site, since most of them provide you with solutions to handle translations.
Most frameworks and apps I've seen in php use arrays, where the original sentence is the key and the translation is the value. So, to make easier to translate it to several languages, the key is in english.
In case you use gettext as suggested, or another aproach, it'll be useful also to parse your code to catch all strings to be translated automatically, since it can be a mess doing it manually when the base code grows and you want to keep up to date your translations.
Take a look at GNU Gettext, its very handy for multilanguage support.
The main idea is that you just wrap your words or phrases into a function, like
echo _g('Hello');
so you do not have any engine changes. You will have to add translation files for each language you are using.
You've come up with 2 solutions for storing the data, but I suggest you need to think further about the architecture and take a more complete view of the lifecycle of each request.
Regarding architecture: neither solution scales up to describe an extensive vocabulary very well - although for one or 2 pages it will suffice. The alternative approach, to manage a translation database (such as gettext) which might be overkill - and performs less optimally with small numbers of pages but importantly performance does not deteriorate significantly with large/multiple dictionaries. A compromise solution might be to have a dataset for each URL/language (which might be extracted from a consolidated database).
If it were me, I would not use either method you proposed for storing the data: parsing XML creates a sginficant overhead for each page request : using \n as a delimiter precludes the use of \n within a translation. Using a serialized PHP array seems to be the least expensive solution.

Creating a bilingual site

I have been working on a site from last 2 years.
Now my client want's make it bilingual, with English and Chinese.
Any idea what should I do for it?
You can have seperate constant files, each file has a bunch of constants in it, then you go through the pages replacing actual sentences with the constants.
Have a cookie that selects the correct constants file that the user has chosen.
This sort of design is good as it allows for more language to be added easily in the future.
It is however a pain in the ass to do.
You could go for some sort of automated translator but it wont read naturally.
I had to do this and since you are working with PHP, I recommend gettext
http://php.net/manual/en/book.gettext.php
And here's an article to get you started on it
http://mel.melaxis.com/devblog/2005/08/06/localizing-php-web-sites-using-gettext/
The benefit of gettext is that the translator never has to touch the code. Rather, the translator works by translating .po files with Poedit ( http://www.poedit.net/ ). You place those .po files in your locale directories from which php-gettext accesses and uses it to replace the strings. Have fun and good luck, I got it to work pretty well
Decent introduction article on the subject:
http://onlamp.com/pub/a/php/2002/11/28/php_i18n.html
We could really do with more info.

What's the most efficient way to setup a multi-lingual website

I'm developing a website that will be available in different languages. It is a LAMP (Linux, Apache, MySQL, PHP) setup, and it makes use of Smarty, mostly for the template engine.
The way we currently translate is by a self-written smarty plugin, which will recognize certain tags in the HTML files, and will find the corresponding tag in an earlier defined language file.
The HTML could look as follows:
<p>Hi, welcome to $#gamedesc;!</p>
And the language file could look like this:
gamedesc:Poing 2009$;
welcome:this is another tag$;
Which would then output
<p>Hi, welcome to Poing 2009!</p>
This system is very basic, but it is pretty hard to control, if I f.e. would like to keep track of what has been translated so far, or give certain users the rights to translate only certain tags.
I've been looking at some alternative ways to approach this, by either replacing the text-file with XML files which could store some extra meta-data, or by perhaps storing all the texts in the database, and retrieving it there.
My question is, what would be the best way to make this system both maintainable and perform well with high user-traffic? Are there perhaps any (lightweight) plugins I could take a look at?
You could give a shot at gettext. It is the way it is done in most C/C++ linux applications and it is an extension to PHP too. The idea is not very different from what you're already doing, but there are tools that ease the mantainance of translations (i.e. poedit).
For user rights to translations, gettext won't be of much help, I think you'll need to do it on your own or look at some frameworks if they have smarter solutions.
Maybe taking a look to gettext lib could help you get some hints http://php.net/manual/en/book.gettext.php hope it helps!
You will need to have a table in your database that you can use to store strings of text, each with an composite ID. the composite ID will be made up of language ID and text node ID.
You will need to give the user a chance to select a preferred language. You should make sure that you either have a default "this has not been translated" for every language you use, or a default language that your entire site can be vied in.
For every bit of text with in your web site, rather then store the text with in the page, you just assign it an ID.
When serving the page, look up the text node ID and preferred language ID and load that string of text, or the string for the default.
in our project, http://pkp.sfu.ca/ojs, we use XML files to store translation key-value pairs. Browse our code: http://github.com/pkp/pkp-lib/blob/master/classes/i18n/PKPLocale.inc.php
We use that class to read the XML files for each locale and in our code we use Locale::translate('locale.key.name');. Similar to gettext, but using an XML file for easier updating.
Looking around at web stuff today I came across this website: http://translateth.is/
It looks simple to use... copy paste in some javascript.

Categories