<?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>Daniel Buschke - Blog &#187; resx</title>
	<atom:link href="http://www.dbuschke.de/blog/tag/resx/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dbuschke.de/blog</link>
	<description></description>
	<lastBuildDate>Wed, 25 Jan 2012 00:32:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Webpart in mehreren Sprachen</title>
		<link>http://www.dbuschke.de/blog/2009/05/26/webpart-in-mehreren-sprachen/</link>
		<comments>http://www.dbuschke.de/blog/2009/05/26/webpart-in-mehreren-sprachen/#comments</comments>
		<pubDate>Tue, 26 May 2009 20:33:00 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[Webparts]]></category>
		<category><![CDATA[Localization]]></category>
		<category><![CDATA[Resource]]></category>
		<category><![CDATA[resx]]></category>
		<category><![CDATA[SPUtility]]></category>

		<guid isPermaLink="false">http://www.dbuschke.de/blog/2009/05/26/webpart-in-mehreren-sprachen/</guid>
		<description><![CDATA[Bei der Webpart Entwicklung ist es oft notwendig, die darzustellenden Labels, Hinweistexte und sonstige Schriftzüge in verschiedenen Sprachen zu halten. Sei es ein freies Webpart, welches für die breite Community gedacht ist, ein Kundenwunsch, weil er mehrere Standorte in verschiedenen Ländern und somit auch anderssprachige Mitarbeiter hat oder sonst ein beliebiger Grund wie z.B. Langeweile. <a href='http://www.dbuschke.de/blog/2009/05/26/webpart-in-mehreren-sprachen/'>[mehr lesen]</a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.dbuschke.de%2Fblog%2F2009%2F05%2F26%2Fwebpart-in-mehreren-sprachen%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.dbuschke.de%2Fblog%2F2009%2F05%2F26%2Fwebpart-in-mehreren-sprachen%2F&amp;source=dbuschke&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Bei der Webpart Entwicklung ist es oft notwendig, die darzustellenden Labels, Hinweistexte und sonstige Schriftzüge in verschiedenen Sprachen zu halten. Sei es ein freies Webpart, welches für die breite Community gedacht ist, ein Kundenwunsch, weil er mehrere Standorte in verschiedenen Ländern und somit auch anderssprachige Mitarbeiter hat oder sonst ein beliebiger Grund wie z.B. Langeweile.</p>
<p>Bei mir trifft heute der zweite Punkt zu und daher möchte ich kurz auf die Lokalisierung eingehen. (kurz deshalb, weil es gar nicht soviel ist <img src='http://www.dbuschke.de/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )</p>
<p>Man nehme ein Webpart seiner Wahl und beginnt zu entwickeln.    <br /><strong></strong></p>
<p><strong>Beispiel</strong>: Wir möchten einen String ausgeben, welches uns in verschiedenen Sprachen begrüßt. Diese Texte sollen in Deutsch und in Englisch erscheinen.</p>
<p>Zuerst legen wir 3 Resourcendateien an, welche beim SharePoint im Verzeichnis 12/Resources/ liegen.   <br />Diese Datei nennen wir <strong>Beispiel.resx</strong>,<strong> Beispiel.en-us.resx</strong> und <strong>Beispiel.de-de.resx.</strong></p>
<p><strong>Inhalt Beispiel.resx</strong> und <strong>Beispiel.en-us.resx</strong></p>
<p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="font-weight: bold; color: black;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- _lcid=&quot;1033&quot; _version=&quot;12.0.4518.1014&quot; _dal=&quot;1&quot; --&gt;</span></span>
<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- _LocalBinding --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;root<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Data</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;wphallotext&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Value<span style="font-weight: bold; color: black;">&gt;</span></span></span>Hello WebPart<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Value<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Data<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/root<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
</p>
<p><strong>Inhalt Beispiel.de-de.resx</strong> </p>
<p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="font-weight: bold; color: black;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- _lcid=&quot;1031&quot; _version=&quot;12.0.4518.1014&quot; _dal=&quot;1&quot; --&gt;</span></span>
<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- _LocalBinding --&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;root<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Data</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;wphallotext&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;Value<span style="font-weight: bold; color: black;">&gt;</span></span></span>Hallo WebPart<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Value<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/Data<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/root<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
</p>
<p>Hierbei ist der einzige Unterschied die LCID und der Wert unseres Keys. Die ersten beiden Dateien sind sogar komplett gleichen Inhalts, worauf ich später nochmal eingehe.</p>
<p>Wenn diese 3 Dateien nun fertig im Verzeichnis hinterlegt sind, können wir diese Strings nun zur Laufzeit im Webpart laden. Dazu bietet das Objektmodell des SharePoints bereits eine Methode, welche 3 Parameter erwartet.</p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<pre style="margin: 0px">string str = <span style="color: #2b91af">SPUtility</span>.GetLocalizedString(<span style="color: #a31515">&quot;$Resources:wphallotext&quot;</span>, <span style="color: #a31515">&quot;Beispiel&quot;</span>, 1033);</pre>
</div>
<ul>
<li>den Source (string)</li>
<li>Resourcenfile (string)</li>
<li>LCID (uint)</li>
</ul>
<p><em>"wphallotext" ist der Key, welcher in den Dateien definiert ist<br />
  <br />"Beispiel" ist das Ressourcenfile (ohne die spezifische Sprachendung)</p>
<p>"1033" steht für die Englisch (natürlich sollte dies nicht hartcodiert sein, sondern z.B. per SPContext.Current.Web.Language ermittelt werden <img src='http://www.dbuschke.de/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )</em></p>
<p>Tja das war es dann auch schon. Kompilieren, anschauen und freuen wie einfach es doch ist. </p>
<p>Aber wozu werden denn nun 3 Dateien gebraucht wenn es nur 2 Sprachen gibt und warum sind <strong>Beispiel.resx</strong> und <strong>Beispiel.en-us.resx</strong> komplett gleich? Die Datei <strong>Beispiel.resx</strong> ist das Default-Resourcenfile und wird benutzt, wenn eine Sprache nicht verfügbar ist. Da Englisch eine Weltsprache ist macht es hier Sinn, diese in die Default Resource zu packen. Wird nun die Webseite in Russisch geladen und wir haben keine Beispiel.ru-ru.resx hinterlegt, wird unser Text in Englisch angezeigt.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dbuschke.de/blog/2009/05/26/webpart-in-mehreren-sprachen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

