How does client GWT determine default time-offset/time-zone and how to change it? - gwt

Based on what GWT at the client side knows about the time-zone? Is it somehow retrieved from user-agent (browser) which in turn has it from OS settings? I tried tinkering with my OS time-zone settings but did not any different.
Is there a way to set the default time-offset/time-zone to be different at the client side code? Reason for this is usage of Date api methods which apparently return results based on the defaul time-offset/zone settings.

You cannot change settings on a user's computer or in a user's browser. That would be a huge security hole.
To display date in the desired time zone, create and pass a TimeZone object to the DateTimeFormat.format() method.

Please have a look at my post Setting locales in gwt.xml do not work where I have explained it with sample code.
Specially look at gwt.xml and where you can define locale.
Hint:
create the DefaultDateTimeFormatInfo based on client (browser/navigator) language
create the DateTimeFormat based on DefaultDateTimeFormatInfo

Related

Form content in multiple languages: View behaviour and model handling

Currently I work an an app where the user can create products for a catalog. The status is, he can do this in one language, data gets send to the backend and saved. The next step would be to make this creation process ready for multiple languages e.g. english or french. The behaviour should be the following, he choses the language inside a drop down field and gets a form in the selected language.
The problems I encountered and my solution process till now:
1) How should the view handling be? Should I create a new fragment for every language and exchange the content? If Im correct that would mean I would need to destroy and create fragements for the languages, right? And then create them with a binded model again.
2) How should I handle the model/models? Should I create one model with the data they share e.g. creation date and create a model with language related attributes? That would be my solution right now.
Maybe you already did something similiar or have some thoughts about this, thanks for any help!
You should do neither of those things. There are mechanisms in place, generally referred to as i18n that help you with this process. UI5 help available here:
https://ui5.sap.com/sdk#/topic/df86bfbeab0645e5b764ffa488ed57dc
and
https://ui5.sap.com/sdk#/topic/5424938fc60244c5b708d71b50a0eee4
In summary, translations should be done using the i18n mechanisms and the oData logon language.
Logging into the application, assuming it's hosted on an SAP gateway or SCP / Launchpad, the user's current logon language will drive at least all standard SAP translatable texts like the labels returned from data elements in your oData services. The appropriate url parameter is sap-language=EN, but it's set automatically from the current browser settings. Generally, you don't have to worry about this.
The same browser settings drive which particular i18n file is loaded. This could be specific like en_US for American English, or fr for French.
If you code your app without any hard coded translations but always follow the rules in the links above, adding a language should be trivial.
These translations could probably be triggered programmatically via a dropdown as well but I have never tried that since it's extra steps for my users.

Content not being displayed in the correct language

I am trying to make this decision on what content (Messages) to be displayed based on the useragent. Everything works correctly when I user query param, or a meta tag. it also works correctly in Firefox. In firefox I change the language from english to french, reload the page and everything comes up correctly. This is baed on the useragent. If I load the page in chrome/IE I get the default (English) only. If I set my system language to French (my other language) everything seems to work as well. Any ideas why setting the language in chrome and IE have no affect no the content? I verified the headers and the requests are being made for French content? What am I missing?
My gwt.xml file is based on the one I found here http://code.google.com/p/google-web-toolkit/source/browse/releases/2.3/user/src/com/google/gwt/i18n/I18N.gwt.xml
It was my understanding that all I needed to add was the following to my gwt.xml
set-configuration-property name="locale.useragent" value="Y"
Also I found the following Why does GWT ignore browser locale? which seems to indicate it won't work in IE but what about chrome?
See http://code.google.com/p/google-web-toolkit/issues/detail?id=4228
TL;DR: there's no reliable way of getting the info you're looking at in JavaScript, the navigator object gives you the locale of the browser (i.e. the one used for the browser's own menus et al.), not the user's language preferences (except in Firefox).
Your best bet is to use a dynamic host page and generate the appropriate <meta> on the server depending on the request headers (i.e. content negotiation).

Zend Translate - Set Locale per User

I'm developing a multi-lingual site.
I've put a Zend_Translate object in the Zend_Registry and I use it to translate all static texts to the selected locale.
My question is how do I change the locale when the user chooses another language?
If I get the translate object from the registry, call setLocale , and put it again in the registry , will it hold only for that user or for the whole application?
Thanks.
You will need to use a plugin for that.
In short: create your plugin and add the routeStartup() and routeShutdown() methods to it. In the former one, set the locale string in a request param and, if needed, also set the requesr URI to contain the locale string. Correct locale string detection is up to you - you can either use a cookie, URL parametre, browser's accepted language header or any combination of the three. In the latter one, create your Zend_Translate object based on the locale you have set earlier.
Here is how it looks like in my CMS.
Here is a tutorial regarding the use of the language parametre in the URL. You may also check how I do it in my CMS (see the _initRouter method).
I hope this info is helpful.
Use Poedit for this purpose ..go thru this link for more
techie.ayyappadas.com/how-do-use-poeditor

GWT Dynamic String Internationalization

Can someone explain how to use this feature. i'm trying to search for an example on the web but not getting it. Also, if at run time, the user wants to change language, how to do so??
According to docs, you can
either specify "locale" GET parameter in your URL, for example:
http://www.domain.com/application.html?locale=fr_CA
or add meta tag to your host HTML page, for example:
You may find complete internationalization example here - it uses locale get parameter approach.
As far as I understand, there's no way to change localization without GWT module re-loading (see here for details).
Both these approaches are static. But for the dynamic approach, this is very hard. Based on the current user's locale, change the ui rendering is NOT that easy...
If any

iPhone settings bundle

I want to allow the user to enter a valid date using the iPhone’s settings application.
I have experimented with many of the PreferenceSpecifiers data node types including date.
I have two issues:
When I specify date as the type, my app within the settings app crashes. Working examples would be greatly appreciated.
Since this approach hasn’t worked for me yet, will I programmatically be able to validate the date that the user enters?
The answer to number 2 is no. The only time you can validate the data entered is the next time your app is launched. None of your app's code is run via the Settings app.
You might consider pulling this setting into your app.
Have you read this guide and this section of the App guide? They describe in detail how the settings like this work.
You won't be able to validate anything a user sets through the Settings application. Also, I don't see Date as a valid setting type anywhere, so I don't even think this is possible through the Settings application.
I would simply create a settings view within the application. That way you can control your custom logic as you see fit.