How to programmatically add a language in drupal 7? - drupal-7

I'm in drupal 7 and I want to programmatically add a language except the default language when I'm writing a new profile. And set it to default.
I don't want to use translation:
http://localize.drupal.org/translate/downloads
Can anyone help?!
Thank you :)

With the Locale locale_add_language function. It is possible to create new languages. It also allows to set newly created language as default. In addition you can set default language by setting "language_default" variable to language object.
variable_set('language_default', $default);

Related

Joomla Language Switcher Missing Language

I am developing and multi language website (3 Languages - Default :English)
I have another two Languages but on my Language Switcher I can only see one of them.
For the default Language the issue I think is the following:
On the menus drop down i can see all flags except the default one as I am not allowed to change the default page (Home Page) of that menu to English. When I try to do it i get the following error:
"Save failed with the following error: The Language parameter for this menu item must be set to 'All'. At least one Default menu item must have Language set to All, even if the site is multilingual."
I haven't been able to understand why I can't see the 3rd Language even if I had followed the exact same procedure with the visible one.
Attaching the link with the instructions I have followed:
https://www.youtube.com/watch?v=cm114SqvUuc
Any help on troubleshooting?

Drupal paths not taking i18n / Multilingual-ness into account?

I have i18n on my Drupal website. If I am currently on the "spanish" version of the site, and I have this code:
drupal_get_path_alias("node/171");
It returns
about-us
I was expecting it to return:
es/about-us
How do I make drupal_get_path_alias aware of languages? Or must I include the prefix myself manually each time?
the language prefix has nothing to do with the path-alias. You could for instance not use path-prefix to determin language, but a cookie. Or maybe evne a sub-domain, or a different tld.
The language-prefix simply has nothing to do with the path-alias

Generate english versions of same content on Drupal?

My website needs to be able to support multiple languages for multiple countries. For example, the US might have English and Spanish, while the UK might only have English. If two countries use the same language, it DOES NOT mean the content is the same.
For this reason, I decided to use the internationalization module (i18n) and I created language codes as follows:
gb-en - UK English
us-en - US English
us-es - US Spanish
I set this up with no issues, but my problem comes in with creating all the default content. For each content type, I want to:
Set the content types default language as "English"
Create translated versions of each content type for each language
I know this will mean that the Spanish content would still be in English, but it's the first step towards translating it.
What is the easiest way to create all these "default" content pages?
You could create a module implementing hook_node_insert(). This module would intercept the creation of a new node (stored with the default language) and create as many copies as needed. Each of these copies should have a different value in the field language. These copies colud be easily stored in the dabase using node_save() function.

Where can I define the default i18n language in JHipster?

I am new to JHipster and I would like to where can I define the default i18n language in JHipster? Is it in a Java Configuration class, in Spring-Boot yaml file, or in Javascript file?
You can set the language you like in the weapp/scripts/app.js file by changing the preferred language line, for instance $translateProvider.preferredLanguage('fr');changes the language to french.
And for JHipster 5.7.2 it's in src/main/webapp/app/app.module.ts under defaultI18nLang.
In the newer version of Jhipster (v 3.0.0 - the one I've been using), you will need to change two places:
src/main/webapp/app/blocks/config/translation.config.js: change the line $translateProvider.preferredLanguage('en'); with your preferred language key (e.g. 'en' -> 'fr');
src/main/webapp/app/blocks/config/translation-storage.provider.js: change the line $cookies.putObject(name, 'en'); with your preferred language key as well.
For jhipster: 4.12.0
Angular: 5
It's in this file: src/main/webapp/app/shared/shared-libs.module.ts under the property "defaultI18nLang"
For jhipster 6.5.1 you should edit defaultI18nLang in /src/main/webapp/app/core/core.module.ts, for example defaultI18nLang: 'ar-ly'
And for JHipster 7.2.0 it's in src/main/webapp/app/app.module.ts under:
translateService.setDefaultLang('en');
// if user have changed language and navigates away from the application and back to the application then use previously choosed language;
const langKey = sessionStorageService.retrieve('locale') ?? 'en';

Incorrect localization when using default language which is different from OS language

I've got a problem with localization - it retrieves incorrect value sometimes. Here is my case:
In every assembly I have NeutralResourcesLanguage set to en-US.
List of available resources is: default (english) fr, de.
So I have English OS and I chose any language - everything is fine (UICulture is set to en, fr or de and Culture is en-US, de-DE or fr-FR respectively).
But when I have German OS and chose English language (UICulture is en and Culture is en-US) -some strings are in German.
Also if I leave Thread.CurrentThread.CurrentUICulture == "de" and Thread.CurrentThread.CurrentCulture = "en-US" then some text will be in english..
Any explanation and solution to this?
You need to use proper language codes, in your case these would be en, fr and de.
Do not use specialised language code when this is not necessary, so use just fr if you have only one French translation.
You should use more specialised ones only only when necessary.
Update: on Windows you cannot fully control the language of the messages you are getting from the OS. Usually they will use your current thread locale but sometimes they will use the OS default language and you can do nothing about it. Just document the behaviour for the users.
I found the problem - I was using DependencyProperty with default value like PropertyMetadata(Resources.Text). And since DP is static it was initializing with system language BEFORE actual localization setting were applied in ApplicationStartup handler.

Resources