Table of contents
1.
Introduction
2.
GWT Internationalization and its Types
2.1.
Types of GWT Internationalization
2.1.1.
Static String Internationalization
2.1.2.
Dynamic String Internationalization
2.1.3.
Localizable Interface
3.
Implementing GWT Internationalization
3.1.
Code
3.2.
Output
3.2.1.
English - 
3.2.2.
French -
3.2.3.
Hindi -
4.
Frequently Asked Questions
4.1.
What is GWT?
4.2.
How is GWT useful concerning Web Applications?
4.3.
What does GWT's Composite mean?
4.4.
What does GWT's HTMLPanel do?
4.5.
What does GWT's PopupPanel do?
5.
Conclusion
Last Updated: Mar 27, 2024
Medium

GWT Internationalization

Author Naman Kukreja
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

As an internet user, you must have come across many applications. Some of them are web-based applications, whereas some are just regular applications. Some are multi-linguistic, whereas others are not. A few are complex, and others are not, so how can you make your applications with many constraints?

Introduction Image

The answer is by using GWT, which refers to Google Web Toolkit. With the help of this, you can make browser applications quickly, and with its feature of internationalization, you can quickly achieve your multi-linguistic application goal. So don’t worry. We will learn about GWT internationalization while moving further in this blog, so let's get on with our topic without wasting time.

GWT Internationalization and its Types

It is a technique used to design an application so that it can be applied to different countries' languages and regions. We cannot internationalize all the data as it will be a waste of time and other resources as well as. So first, we segregate the important data, or you can say that the usage data. Generally, GWT requires segregation of usage data, which will be internationalized. You can refer to this as similar to java programming as the resource bundles are used to implement internationalization in the java programming language by creating a .properties file for each locale that needs to be supported.

Types of GWT Internationalization

There are mainly three types of GWT internationalization. We will learn about all three of them in this blog section.

Static String Internationalization

  • It is one of the earliest and most valuable techniques for translating parameterized and constant strings.
  • The reason for this technique to be simple is the ease of its implementation, as it requires significantly less overhead.
  • Static string internationalization uses standard Java properties files to store translated strings and parameterized messages, and strongly-typed Java interfaces are created to retrieve their values.

Dynamic String Internationalization

  • As the name suggests, this technique is dynamic, which means it can be changed. It is slower than static string but advantageous as it can be changed according to requirements.
  • Applications that employ this strategy are displayed on the module's home page as localized strings. This method eliminates the requirement for them to be recompiled whenever a new locale is added.
  • This method must be used if the GWT application is to be integrated with an existing server-side localization system.

Localizable Interface

  • It is the most important and powerful technique for implementing the interface.
  • It comes under the category of advanced internationalization techniques that are used rarely.
  • We need to develop a localizable interface at an advanced level for simple string substitution. Additionally, it produces customized types in localized form.

Implementing GWT Internationalization

To implement GWT internationalization, follow the steps below in the same order as explained in this blog section.

Step1: Implement I18N: Here, mention every locale value you need to use and that application requires. You can achieve this by extending the locale value in the module’s XML file as shown below:

<module>  
<inherits name="com.google.gwt.i18n.I18N"/>  
<inherits name="com.google.gwt.user.User"/>  
<entry-point/>  
<extend-property name="locale" values="hi"/>  
<extend-property name="locale" values="fr"/>  
</module>  


Step 2: For every locale, create a .locale file: All resource bundles must differ in their locale-specific suffix but should have the same base name. The message lookup method takes the base name, current locale, and message key into account. Include the source package with all of the .properties files.

Now we will see some properties file.

We will create a locale that supports the french locale.

AppConstants_fr.properties contains the french locale, and its key-value pairs are shown 

Below:

username: Nom d'utilisateur  
password: Mot de passe  
login: connexion 


Now we will see the default locale in the AppConstrins.properties file as shown below:

username: Username  
password: Password  
login: Login  


Step 3: Here, we will create an interface corresponding to the properties file

  • First, create an interface that extends GWT’s constraints interface.
  • We can use resource bundles to bind that interface.
  • Each method corresponds to a key in the interface.
  • The base name of the interface and properties file must be exact.
public interface AppConstants extends Constants {  
  
String username();  
String password();  
String login();  
  
}  


Step 4: Setup the Entry Point Class

public void onModuleLoad() {  
// Getting the values from resource bundle through interface methods  
        Label username=new Label(constants.username());  
        Label passsword=new Label(constants.password());  
     PasswordTextBox pbox=new PasswordTextBox();          
     TextBox ubox=new TextBox();  
        Button button = new Button(constants.login());  
    }  

Code

public class LoginI18nDemo implements EntryPoint {  
public LoginI18nDemo () {}  
AppConstants constants=(AppConstants)GWT.create(AppConstants.class);  
public void onModuleLoad() {  
Label username=new Label(constants.username());  
Label passsword=new Label(constants.password());  
TextBox ubox=new TextBox();  
PasswordTextBox pbox=new PasswordTextBox();  
Button button = new Button(constants.login());  
Grid g=new Grid(3,2);  
g.setWidget(0,0,username);  
g.setWidget(0,1,ubox);  
g.setWidget(1, 0, passsword);  
g.setWidget(1,1,pbox);  
g.setWidget(2, 1, button);  
HorizontalPanel links=new HorizontalPanel();  
Anchor french=new Anchor("French",GWT.getHostPageBaseURL()+"?locale=fr");  
Anchor hindi=new Anchor("Hindi",GWT.getHostPageBaseURL()+"?locale=hi");  
links.add(french);  
links.add(hindi);  
links.setSpacing(5);  
RootPanel.get().add(g);  
RootPanel.get().add(links);  
    }  
}

Output

English - 

French -

Hindi -

Frequently Asked Questions

What is GWT?

Google Web Toolkit or GWT is a development toolkit used to build and optimize complex browser-based applications.

How is GWT useful concerning Web Applications?

With significant client-side work and little server-side chatter, highly responsive web apps can be developed with GWT.

What does GWT's Composite mean?

This widget is an example of a type of widget that can hide the methods of another widget it is wrapping. A composite functions precisely as if the widget it wraps had been added when it is introduced to a panel.

What does GWT's HTMLPanel do?

This widget shows an HTML-containing panel that allows child widgets to be attached to specific HTML components.

What does GWT's PopupPanel do?

This widget represents a panel that can appear over other widgets. It covers up any previously created popups and the browser's client area.

Conclusion

In this blog, we have discussed GWT's internationalization with its use and types. We have discussed all its types in detail, followed by the implementation of GWT internationalization with proper code and output.

You can refer to GWT's Developer Guide to learn more about GWT. The main ideas, resources, and libraries you'll use to create web applications with GWT are covered in this guide. You can also explore some more articles on GWT GridGWT StackLayoutPanelGWT RootLayoutPanelGWT MVP, and GWT Charts. You can visit Coding Ninjas Studio to get access to premium quality content like guided paths, Questions, and much more.

Nevertheless, you may consider our paid courses to give your career an edge over others.

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Live masterclass