<?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>Mas que Wordpress - Tutoriales, recursos web, JQuery y PHP, Wordpress , twitter y muchos recursos más &#187; multilenguaje</title>
	<atom:link href="http://www.masquewordpress.com/tag/multilenguaje/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.masquewordpress.com</link>
	<description>Tutoriales y recursos web sobre JQuery , PHP, Wordpress , twitter. Aprende diseño web y programación</description>
	<lastBuildDate>Mon, 06 Feb 2012 15:02:11 +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>Como hacer una web multilenguaje</title>
		<link>http://www.masquewordpress.com/como-hacer-una-web-multilenguaje/</link>
		<comments>http://www.masquewordpress.com/como-hacer-una-web-multilenguaje/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 22:54:14 +0000</pubDate>
		<dc:creator>Damian</dc:creator>
				<category><![CDATA[Tutoriales]]></category>
		<category><![CDATA[multilenguaje]]></category>

		<guid isPermaLink="false">http://masquewordpress.com/?p=363</guid>
		<description><![CDATA[Para detectar el idioma del navegador y hacer una web multilenguaje existen diversos métodos. Yo particularmente suelo usar el siguiente: Primero creo el archivo lang-functions.php 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 [...]]]></description>
			<content:encoded><![CDATA[<p>Para detectar el idioma del navegador y hacer una web multilenguaje existen diversos métodos. Yo particularmente suelo usar el siguiente:</p>
<p>Primero creo el archivo<strong> lang-functions.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/*
&nbsp;
    =============================================================================
&nbsp;
     Funcion: detectar_idioma_navegador() 
&nbsp;
    -----------------------------------------------------------------------------
&nbsp;
     Proposito: Esta funcion detecta el idioma por defecto seleccionado en el navegador del visitante.
&nbsp;
     Si no se detecta un lenguaje valido, se asigna el selecionado por defecto.
&nbsp;
&nbsp;
&nbsp;
    =============================================================================
&nbsp;
    */</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> detectar_idioma_navegador<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$conf</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
    <span style="color: #000088;">$languages</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(;q=\d+.\d+)/i'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #990000;">getenv</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP_ACCEPT_LANGUAGE'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
    <span style="color: #000088;">$bol_language_detected</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
    <span style="color: #666666; font-style: italic;">// Comprobamos si el navegador usa alguno de los idiomas que hemos predefinido.</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$conf</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lang_enabled'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$tmp_arr_language</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$tmp_arr_language</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$languages</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000088;">$tmp_str_language_detected</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tmp_arr_language</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$bol_language_detected</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Si el navegador usa uno de los idiomas seleccionados, se devuelve el path del fichero de idioma</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// En caso contrario, se devuelve el path del idioma original</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$bol_language_detected</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$tmp_str_language_detected</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$conf</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lang_default'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Una vez creado el archivo lo incluyo de la siguiente manera:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;languages/lang-functions.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		<span style="color: #000088;">$conf</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lang_default'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'es'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// idioma por defecto</span>
&nbsp;
		<span style="color: #000088;">$conf</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lang_enabled'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'es'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'en'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$conf</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lang'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> detectar_idioma_navegador<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lang'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$conf</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lang'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lang'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">// Podemos crear un link como por ej una bandera para permitir cambiar el idioma al usario</span>
&nbsp;
		<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;languages/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$conf</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lang'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Por último nos queda crear los archivos de idiomas de la siguiente forma:</p>
<p><strong>es.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #666666; font-style: italic;">// Spanish language file </span>
   <span style="color: #990000;">setlocale</span><span style="color: #009900;">&#40;</span>LC_ALL<span style="color: #339933;">,</span><span style="color: #0000ff;">'es_ES'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;_MENSAJE&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;HOLA SOY UN MENSAJE EN ESPAÑOL&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>en.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span> <span style="color: #666666; font-style: italic;">// English language file </span>
   <span style="color: #990000;">setlocale</span><span style="color: #009900;">&#40;</span>LC_ALL<span style="color: #339933;">,</span><span style="color: #0000ff;">'es_ES'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;_MENSAJE&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Hi im a English message&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>En la web escribiriamos <strong>echo (_MENSAJE); </strong> y según el idioma del navegador aparecerá de una forma u otra.</p>
<p>Espero que haya servido de ayuda</p>
]]></content:encoded>
			<wfw:commentRss>http://www.masquewordpress.com/como-hacer-una-web-multilenguaje/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

