<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Farrworks &#187; Uncategorized</title>
	<atom:link href="http://farrworks.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://farrworks.com</link>
	<description>Technology, Work, Life, Play, and everything else in between the ears of an Ian...</description>
	<lastBuildDate>Fri, 26 Feb 2010 22:17:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>seperating CakePHP&#8217;s translation files into &#8220;Domains&#8221;</title>
		<link>http://farrworks.com/2009/07/seperating-cakephps-translation-files-into-domains/</link>
		<comments>http://farrworks.com/2009/07/seperating-cakephps-translation-files-into-domains/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 15:14:42 +0000</pubDate>
		<dc:creator>Ian Farr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://farrworks.com/?p=211</guid>
		<description><![CDATA[Lately I have been doing much work on translation, making sure that one of my main CakePHP projects can be easily translated. By default CakePHP keeps everything in one big &#8220;default.po&#8221; file&#8230;but there is a way to use other files, and use CakePHP built-in methods to access these different &#8220;po&#8221; files.

By default, as many bakers [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I have been doing much work on translation, making sure that one of my main CakePHP projects can be easily translated. By default CakePHP keeps everything in one big &#8220;default.po&#8221; file&#8230;but there is a way to use other files, and use CakePHP built-in methods to access these different &#8220;po&#8221; files.<br />
<span id="more-211"></span></p>
<p>By default, as many bakers know, CakePHP has a globally available function to translate strings: the __() function available in basics.php in the cake distribution. This function is great, and is very easy to use, but it will only work on one file (the default.po file). So all your translation string must exist in that one file&#8230;not very practical at all.</p>
<p>In one of my CakePHP projects, this translation file was getting way to big, and since I shared this source with many different projects, I had all sorts of junk in there &#8211; some for this project, some for that project &#8211; it was just a mess.</p>
<p>After looking around, I didn&#8217;t find all that much, so I decided to go looking through the source, and found that the basics.php is where __() had it&#8217;s home. It wasn&#8217;t very long after that where I found out that __() had a couple of brothers. namely __d().</p>
<p>I quickly tested out __d(), and found that this is what I was looking for all along. It works very similar to __(), in that it looks for a string to translate and returns the translation if one is found. If one is not found then the passed string is simply returned. What is different about it is that it accepts a  &#8220;domain&#8221;.</p>
<p>I found that the default translation domain is&#8230;well&#8230;&#8221;default&#8221;. If you use __d(&#8220;default&#8221;,&#8221;my string I want translated&#8221;, true), it will work exactly like __(&#8220;my string I want translated&#8221;, true) &#8211; it will look for a msgid called &#8220;my string I want translated&#8221; in the current locale&#8217;s default.po file. </p>
<p>Now that I found this out, I quickly started separating that giant &#8220;default.po&#8221; file into other .po files in the current locale directory. Once this was done (not a trivial task by the way), it was just a matter of putting the files name (without the .po) in the &#8220;domain&#8221; parameter (the first parameter) of the __d() function.</p>
<p>Simply put, I seperated the translation strings by web site section. All my &#8220;admin&#8221; screens had a seperate file for admin translations (manage.po), as well as any project specific translations in [projectname].po, and I kept default.po for all the stuff that was &#8220;constant&#8221;..that is the stuff that I am 99.99% sure that I will use on all projects that I use this source for. </p>
<p>Once this was done, if I wanted to translate a string from the admin translation file, I just had to use __d(&#8220;manage&#8221;, &#8220;translate this&#8221;, true). done.</p>
<p>I find that this makes things much easier to work with, and allows you to organize your translation strings into files in whatever way is logical to you. This should also help out in situations where multiple people are working on the same translation, as you could divide the work by file, or be more granular and have more files/domains for translations&#8230;</p>
<p>I was/am still a happy guy who continues to bake cake[php]&#8217;s.</p>
]]></content:encoded>
			<wfw:commentRss>http://farrworks.com/2009/07/seperating-cakephps-translation-files-into-domains/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
