Skip to main content
added 2102 characters in body
Source Link
Free Radical
  • 15.1k
  • 9
  • 48
  • 83

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.

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 pelase note that you don't have to use the index named "English" for English. 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 variable. Let say you assign TX 12345" (translation 12345) 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 12345"); to get Drupal to pick this up. Now go to Drupal's translation interface and search for "TX 12345". 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 12345); 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 12345);, but make sure the page's default language is "Ingles" (not English). So 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. And there is a simpler way!

Instead of picking obscure strings such as "TX 12345" to represent "¡Hola, mundo!", you pick something easy to remember, for example "Hello, world!" - since that is the same phrase in English. Otherwise, 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" showing up as am index in Drupal's translation interface, you'll see the index "Hello, world!". But just like before you enter "¡Hola, mundo!" as the Spanish original, 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, 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.

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 please note that you don't have to use the index named "English" to 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 an index for lookup in the translation table. Let say you assign "¡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("¡Hola, mundo!"); to get Drupal to pick this up. Now go to Drupal's translation interface and search for "¡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("¡Hola, mundo!"); 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("¡Hola, mundo!");, but make sure the page's default language is "Ingles" (not English). 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 there is a simpler way!

Instead of using "¡Hola, mundo!" as an index to "¡Hola, mundo!", you pick "Hello, world!" as your index. Otherwise, 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 "¡Hola, mundo!" showing up as am index in Drupal's translation interface, you'll see the index "Hello, world!". But just like before must enter the string "¡Hola, mundo!" as the Spanish original phrase, and for translation into "Ingles", you enter "Hello, world!".

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.

added 2102 characters in body
Source Link
Free Radical
  • 15.1k
  • 9
  • 48
  • 83

Drupal'sIf 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 is. But pelase note that you don't have to use the index named "English" for English. You can define new languages, and even invent them, so the inputlet us define a target language is alwayscalled "Ingles", and use that for English. There

Now for each phrase you want to translate fro Spanish to English, you need to assign a variable. Let say you assign TX 12345" (translation 12345) to the Spanish phrase "¡Hola, mundo!". On at least one page (it doesn't matter if it is no problem usingSpanish, English or "Ingles, you must have t("TX 12345"); to translate from Spanishget Drupal to English, butpick this up. Now go to Drupal's translation interface and search for "TX 12345". When you've found it to work, you must do itcan enter the correct way. The correct way may seem "backwards" to youstrings for the Spanish original ("¡Hola, but it worksmundo!") 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.

If you're goingWhen done, you should be able to use t(TX 12345); on a page with Spanish as its default language to make the user see "¡Hola, your original text insidemundo!". To get the translation into English, you also use t(TX 12345); function must be in English, but make sure the page's default language is "Ingles" (not English). So this is how you use t('Hello, world');-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). Even if the page

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. And there is primarely supposeda simpler way!

Instead of picking obscure strings such as "TX 12345" to be in Spanishrepresent "¡Hola, mundo!", you pick something easy to remember, for example "Hello, world!" - since that is the text insidesame phrase in English. Otherwise, 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"); must be in (it doesn't matter if that page is Spanish, English or "Ingles). Then you go to

Now, instead of "TX 12345" showing up as am index in Drupal's translation interface and, you'll see the index "Hello, world!". But just like before you enter "¡Hola, mundo!" as the Spanish original, and for translation ("¡Holainto "Ingles", mundoyou enter "Hello, world!"). Now So we've done away with the obscure index, if your page's default languagebut everything else is Spanish, the Spanish translation will show upsame. You'll only see

However, there it is also possible to get rid of the English text on a Spanish page if no Spanish translation existsinvented language "Ingles". And It just so happens that if someone visit's a page whosethe default language for a page is English (not "Ingles"), they'll seet();will not look up the string in the table but just return the index. And since we're now using English text, so itphrases as index that index will be correctly translated toin English on those pages whosewhere the default language is English.

To sum up: If your page's So we can stop using the the invented language is"Ingles" and instead rely on getting the index back on English pages, while on Spanish pages, then the userindex will see "¡Hola, mundo!",be used for table lookup and if your page's language is English, then the userwe will see "Hello, world!"get a Spanish string back.

Drupal's default language is English, so the input language is always English. There is no problem using t() to translate from Spanish to English, but for it to work, you must do it the correct way. The correct way may seem "backwards" to you, but it works!

If you're going to use t(), your original text inside the t() function must be in English (t('Hello, world');). Even if the page is primarely supposed to be in Spanish, the text inside t() must be in English. Then you go to Drupal's translation interface and enter the Spanish translation ("¡Hola, mundo!"). Now, if your page's default language is Spanish, the Spanish translation will show up. You'll only see the English text on a Spanish page if no Spanish translation exists. And if someone visit's a page whose default language is English, they'll see the English text, so it will be correctly translated to English on those pages whose default language is English.

To sum up: If your page's language is Spanish, then the user will see "¡Hola, mundo!", and if your page's language is English, then the user will see "Hello, world!".

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 pelase note that you don't have to use the index named "English" for English. 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 variable. Let say you assign TX 12345" (translation 12345) 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 12345"); to get Drupal to pick this up. Now go to Drupal's translation interface and search for "TX 12345". 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 12345); 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 12345);, but make sure the page's default language is "Ingles" (not English). So 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. And there is a simpler way!

Instead of picking obscure strings such as "TX 12345" to represent "¡Hola, mundo!", you pick something easy to remember, for example "Hello, world!" - since that is the same phrase in English. Otherwise, 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" showing up as am index in Drupal's translation interface, you'll see the index "Hello, world!". But just like before you enter "¡Hola, mundo!" as the Spanish original, 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, 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.

deleted 36 characters in body
Source Link
Free Radical
  • 15.1k
  • 9
  • 48
  • 83

If you look at the API for t() - https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/t/7 - you'll notice that it allows you do specify $langcode in the options array, however, that is a method to override the output language - not the input.

Drupal's default language is English, so the input language is always English. There is no problem using t() to translate from Spanish to English, but for it to work, you must do it correctlythe correct way. The correct way may seem "backwards" to you, but it works!

If you're going to use t(), your original text inside the t() function must be in English (t('Hello, world');). Even if the page is primarely supposed to be in Spanish, the text inside t() must be in English. Then you go to Drupal's translation interface and enter the Spanish translation ("¡Hola, mundo!"). Now, if your page's default language is Spanish, the Spanish translation will show up. You'll only see the English text on a Spanish page if no Spanish translation existexists. However, And if someone visit's a page whose default language is English, they'll see the English text, so it will be correctly translated to English on those pages whose default language is English.

To sum up: If your page's language is Spanish, then the user will see "¡Hola, mundo!", and if your page's language is English, then the user will see "Hello, world!".

Going the other way is AFAIK not possible.

If you look at the API for t() - https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/t/7 - you'll notice that it allows you do specify $langcode in the options array, however, that is a method to override the output language - not the input.

Drupal's default language is English, so the input language is always English. There is no problem using t() to translate from Spanish to English, but for it to work, you must do it correctly. The correct may seem "backwards" to you, but it works!

If you're going to use t(), your original text inside the t() function must be in English (t('Hello, world');). Even if the page is primarely supposed to be in Spanish, the text inside t() must be in English. Then you go to Drupal's translation interface and enter the Spanish translation ("¡Hola, mundo!"). Now, if your page's default language is Spanish, the Spanish translation will show up. You'll only see the English text on a Spanish page if no Spanish translation exist. However, if someone visit's a page whose default language is English, they'll see the English text.

To sum up: If your page's language is Spanish, then the user will see "¡Hola, mundo!", and if your page's language is English, then the user will see "Hello, world!".

Going the other way is AFAIK not possible.

If you look at the API for t() - https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/t/7 - you'll notice that it allows you do specify $langcode in the options array, however, that is a method to override the output language - not the input.

Drupal's default language is English, so the input language is always English. There is no problem using t() to translate from Spanish to English, but for it to work, you must do it the correct way. The correct way may seem "backwards" to you, but it works!

If you're going to use t(), your original text inside the t() function must be in English (t('Hello, world');). Even if the page is primarely supposed to be in Spanish, the text inside t() must be in English. Then you go to Drupal's translation interface and enter the Spanish translation ("¡Hola, mundo!"). Now, if your page's default language is Spanish, the Spanish translation will show up. You'll only see the English text on a Spanish page if no Spanish translation exists. And if someone visit's a page whose default language is English, they'll see the English text, so it will be correctly translated to English on those pages whose default language is English.

To sum up: If your page's language is Spanish, then the user will see "¡Hola, mundo!", and if your page's language is English, then the user will see "Hello, world!".

deleted 141 characters in body
Source Link
Free Radical
  • 15.1k
  • 9
  • 48
  • 83
Loading
deleted 141 characters in body
Source Link
Free Radical
  • 15.1k
  • 9
  • 48
  • 83
Loading
added 80 characters in body
Source Link
Free Radical
  • 15.1k
  • 9
  • 48
  • 83
Loading
added 1 character in body
Source Link
Free Radical
  • 15.1k
  • 9
  • 48
  • 83
Loading
Source Link
Free Radical
  • 15.1k
  • 9
  • 48
  • 83
Loading