Implementation of Multiple language based on url specific - django

I am using language translation in my project.But it only translate the strings if I set the highest priority to respective language in my browser.
e.g.
If i am using two language en and es for translation then it will display data in spanish if I have set spanish as my default language in my browser.
My translation is working because it only displayed that data in spanish which i have specified in my Django.po file.
So What i want is if i specify the language in url as www.asd.com/?lang=es then it must display the data in spanish.
So please suggest me what i have to do for that.

I think you are looking django-localeurl.
A Django application that allow you to specify the language of a page in the URL.
For Installation click here.

Related

Changing language with React Native and django-modeltranslation

I would like to add option to mobile app to change language. Im using django on backend and RN as mobile. So I installed django-modeltranslation and added my model I want to translate. On mobile I display available languages. When user clicks on specific language I would like to get translated data. I have huge problem to create logic how to do it. I'm not asking about code just some hints and idea
EDIT:
For example: I added translation from django-modeltranslation to my model (i.e GameTask with field title, description etc). In my settings.py I have declared languages ('en','de','uk',etc) and added translations in database (for every field of GameTask, I added title(en), title(de) etc). When I change language in settings.py, values on mobile are changing too (so working as intended). So im not storing any translated text in app files, just in database (except of static errors and informations). Now I just want to send info from mobile with chosen language and activate this language on backend to return content in specific language
If you want to completely make your application multi-language, you need two things.
Translation system for your app
Translation system for your api.
First, use a pre-built context api or create your own to support changing language in-app. Something like this: https://medium.com/#ally_20818/multi-language-text-with-react-native-react-context-b76d5677346d
When user changes the language, store the language name or key in async-storage or some other database.
Change the texts in the react-native side based on the selected language.
When you're making a api call, send the selected language too. Get the selected language on api side and return appropriate texts based on language.
UPDATE:
Since you're not storing any text on react-native side, you only need to add a picker (react-native-picker/picker is a native picker) and store the selected language key (en, de, uk etc in your case) in a database like react-native-async-storage. When you're making api requests with react-native, include an additional header or post data which includes selected language key. And you can get and use that key in your django back-end.

Convert webpage in other language?

I have created one django appEngine website in english language i want to convert that site in other language like hindi gujrati and much more language and give just one button on top of that converet in gujrati, hindi and any other language and hole site will be convert in to that perticular language.
Like in google crome that provide that facility to convert site in any language.
You can do it in two ways -
Use Django's own i18n and l10n feature. Provide your own translations and urls to use them.
Use Google's translation toolbar, that shows an option like you mentioned happens in Google chrome. It'll show a toolbar with translate button with a language option and using it will translate whatever text you have on the page.

How to translate single page in django?

I have only one page i want to translate and im using downloaded application (with locale folder in it).
I want to get output from this app with translated values on one single page.
How can i tell the the template or view to show translated values?
I'm assuming that you want the page to be in a different language than what you have set for your website.
Here is two lines of the code of the middleware which manages languages in our dual-language website but I guess in your case, it can be placed at the beginning of your view function:
django.utils.translation.activate(desired_lang)
request.LANGUAGE_CODE = django.utils.translation.get_language()

default languages for items and folders in sitecore

I'm working in a multi-site, multi-lingual sitecore project, and from time to time, someone adds lots of content on certain sub-site, fight hours with the publishing and being unable to see the updated content, and eventually realise after a couple of hours that all the input was in the wrong language for the sub-site.
So i'm wondering if there is a way in sitecore to support the following:
a folder (for a sub-site) that supports that after clicking an existing item below it, the language automatically changes to the default language for the site folder
since the language is automatically changed, new items created below that folder will be created in the default sub-site language, unless the user explicitly changes it to something else
If the above is impossible or not supported, an excellent workaround would be to be able to change the language of an item language version (say, i created an english version for a page on a spanish site with all the content in spanish, so i want to tell sitecore that i want to make this version actually the spanish version, without going into copying fields manually in the translate ui
It sounds like you might want to consider a few things:
The Language Fallback Provider - this allows you to have have content fallback from one language to another if it doesn't exist.
A custom extension (maybe an event handler for item:creating or item:created) to Sitecore to switch the context language based on where an editor is creating an item.
Just ideas right now...
An alternative approach would be to work with language read and language write security settings for your content contributors.
If your contributor for your Spanish site should only be adding items in Spanish then configure their access settings so that they aren't allowed to create content in other languages.
If you have a lot of content that has been entered in the wrong language then you can use the Globalization - Export language tool (from the Start menu) to export it to an XML file, manually replace the language tags (this is as simple as a search and replace on "en>" -> "es-ES>" for example) and then reimport it in the new language using the Globalization - Import language tool. Warning though: this WILL overwrite any existing versions.

How can I change the current language that users see for a Sitecore site?

Let's say I have a web site that is translated in to two languages - English and Spanish. I want to give the users a toggle switch at the top of the page that allows them to switch back and forth between the two languages. How would I do that? I don't want to set up different websites. I only want one website. I just want the user to be able to click on a button or link or something and go from English to Spanish. Now as they move around the site they are viewing the entire site in Spanish. Then if they click on the button or link again they would go back to English. Is there something I have to do in the code behind to tell Sitecore to "use" a different language?
You can switch the context language using "sc_lang" query string parameter. For example:
http://youwebsite.com?sc_lang=en
Typically in Sitecore you will want to represent the language using the built-in URL prefixes, e.g. http://www.example.com/en or http://www.example.com/es. We often use a cookie that we read in the httpRequestBegin pipeline to enhance the Sitecore LanguageResolver. Your language "toggle" could appropriately set that cookie.
See this article by John West for more detail and sample code.
https://community.sitecore.net/technical_blogs/b/sitecorejohn_blog/posts/repost-overriding-sitecore-39-s-logic-to-determine-the-context-language
You can write your own LanguageResolver Pipeline to do this.
Or you can extend your URL by Using the sc_lang querystring Parameter eg.: sc_lang=en-EN or sc_lang=de-DE. If you have configured your linkmanager fine this should work.