If you don't want to translate from English to Spanish, but the other way, there is a small quirk in Drupal localization framework. The name "English" in Drupal is reserved as the default index for languages, so you can't use that name for the target language. But pelaseplease note that you don't have to use the index named "English" forto hold English strings. You can use anything for that index. You can define new languages, and even invent them, so let us define a target language called "Ingles", and use that for English.
Now for each phrase you want to translate fro Spanish to English, you need to assign a variablean index for lookup in the translation table. Let say you assign TX 12345" (translation 12345)"¡Hola, mundo!" to be the index corresponding to the Spanish phrase "¡Hola, mundo!". On at least one page (it doesn't matter if it is Spanish, English or "Ingles, you must have t("TX"¡Hola, 12345"mundo!");
to get Drupal to pick this up. Now go to Drupal's translation interface and search for "TX 12345""¡Hola, mundo!". When you've found it, you can enter the correct strings for the Spanish original ("¡Hola, mundo!") into the field for "Spanish" and its translation into English ("Hello, world!") into the field for "Ingles". Do that with every phrase you want to translate from Spanish to English.
When done, you should be able to use t(TX"¡Hola, 12345mundo!");
on a page with Spanish as its default language to make the user see "¡Hola, mundo!". To get the translation into English, you also use t(TX"¡Hola, 12345mundo!");
, but make sure the page's default language is "Ingles" (not English). So this This is how you use t()
-to translate from Spanish to "Ingles" (which is just an alias for "English" - we must use this alias since Drupal has reserved "English" to hold the default translation index).
However, you may find it a bit awkward to "invent" a new language called "Ingles" and to use hard to remember variables like "TX 12345" to represent common phrases. AndAnd there is a simpler way!
Instead of picking obscure strings suchusing "¡Hola, mundo!" as "TX 12345"an index to represent "¡Hola, mundo!", you pick something easy to remember, for example "Hello, world!" - since that is the same phrase in Englishas your index. OtherwiseOtherwise, you proceed like before - to get this variable into Drupal's inserted into translation interface, you must on at least one page have t("Hello, world");
(it doesn't matter if that page is Spanish, English or "Ingles).
Now, instead of "TX 12345""¡Hola, mundo!" showing up as am index in Drupal's translation interface, you'll see the index "Hello, world!". But just like before youmust enter the string "¡Hola, mundo!" as the Spanish original phrase, and for translation into "Ingles", you enter "Hello, world!". So we've done away with the obscure index, but everything else is the same.
However, now there it is also possible to get rid of the invented language "Ingles". It just so happens that if the default language for a page is English (not "Ingles"), t();
will not look up the string in the table but just return the index. And since we're now using English phrases as index that index will be in English on pages where the default language is English. So we can stop using the the invented language "Ingles" and instead rely on getting the index back on English pages, while on Spanish pages, the index will be used for table lookup and we will get a Spanish string back.