Showing posts with label i18n. Show all posts
SAPUI5 Application Project Structuring

SAPUI5 Application Project Structuring

Sanjo Thomas•23:45:00


SAPUI5 Application Project Structuring
With the release of latest update of SAPUI5, project structure has been changed slightly. All the configuration that used to be maintained in the configuration file is now managed by manifest.json , moreover it takes care of routing, which previously was maintained by component.js. Similarly, there have been many more changes. An example with the latest project structure is shown.
This is a sample project structure, which almost covers every aspect.
The WebContent contains all the folders, including Component-preload.js, Component.js, index.html , and manifest.json.  Gulpfile  and node_modules are of no use here, it is mainly used to create the Component-preload.js file.
·         The First change that you notice is, now the controller files are kept separate in the controller folder, and not in the view folder itself. The controller folder include all the javascript files.
 
·         Then comes the CSS folder, which include customizing the sap ui5 application. Add any css files in this folder.
·         Next is the i18n folder, which is used for Globalization purpose. It includes i18n files for particular languages.
·         localService and test folder is used for mockserver, which consists of mockdata , metadata,  mockserver.js and testService.html which acts an index.html file for the mockserver.
·         model folder consists of the formatter.js file.
·         util folder consists the dialog.js file, if it is used in a particular project, and similarly the fragment files are contained in the view folder.
·         Next comes the view folder, which now purely consists only the views, both xml or maybe javascript files too. Moreover, it also includes the fragment files too.
·         Component-preload.js file is mainly used for optimization purpose, it is created using grunt operations or maybe using gulpfile.
·         Component.js file is used here for declaring the models, (odata, json, or i18n)but in the latest version of sapui5, that step is also done in the manifest.json file.
                Moreover, here the router initialization is also done.
·         Index.html file serves the same purpose here, we declare the shell  here. And all the library files are loaded in index.html. Mainly there is no change in the index file. It serves the same purpose similar to what it used to serve in previous versions.
·         Manifest.json file here is used to declare the OData, here  the version of sap.ui5, sap.ui, sap.app is done. Moreover, the routes are defined here itself, and not in the component.js file.

Go through my video from Youtube, on Project Structuring:

In the First session I have covered, views, controllers, Component.js, and Manifest.json

 


In the Second Session, I have covered the models, i.e JSON model

 

In the third Session, I have covered the Internationalization topic 


Read more
Internationalization(i18n)

Internationalization(i18n)

Sanjo Thomas•02:27:00


Globalization and localization
It is a way, how a computer software could be adapted to different languages. Internationalization(i18n) is actually the process of designing a software so that it can be adapted to different languages across the world, here 18 stands for number of alphabets between I & n.  Localization is the process of adapting internationalized software for a particular region or language by adding locale-specific components and translating text.

Here's my video in youtube, explaining the concept of Globalization


We use internationalization and localization in our Sapui5 application for replacing the hard coded text from the application. It is one of the best practices of SAP to use i18n for hard coded texts.  Generally we use Resource Model for defining, since it is one way binding (sap.ui.model.resource.ResourceModel)  
The i18n model is set up in the Component's initialization section, or it could also be defined in the manifest.json file.
//set i18n model
var rootPath = jQuery.sap.getModulePath("sap.ui.demo.tdg");

Var i18nModel = newsap.ui.model.resource.ResourceModel({
bundleUrl : "i18n/messageBundle.properties"
});
oView.setModel(i18nModel, "i18n"
);
Now create a folder named i18n in the project directory and maintain i18n files according to the languages.
The configuration specifies the relative location of the resource bundle. This is made absolute (in relation to our app's namespace) by use of the jQuery.sap.getModulePath utility function, and then used to create the named model, before it is set on the component.
Now in the i18n.properties file, enter all the hard coded text that has been used in the application. And bind the data using the i18n model
Example
<Table id="idOrderTable">

      <columns>
            <Column width="8em">
                  <Text text="{i18n>s3OrderColumnSales}" />
            </Column>
            <Column>
                  <Text text="{i18n>s3OrderColumnDelivery}" />
            </Column>
            <Column>
                  <Text text="{i18n>s3OrderColumnOrder}" />
            </Column>
            <Column>
                  <Text text="{i18n>s3OrderColumnRequested}" />
            </Column>
            <Column>
                  <Text text="{i18n>s3OderColumnAmount}" />
            </Column>
      </columns>
</Table>

Here we have used a table and, the column text name is a hard coded value, hence we are using i18n model for the same.  Now we have to maintain the same fields in the i18n.properties file.
s3OrderColumnSales=Sales Order
s3OrderColumnDelivery=Delivery Status
s3OrderColumnOrder=Order Date
s3OrderColumnRequested=Requested Date
s3OderColumnAmount=Order Amount
Hence this is done, now to serve the real purpose of i18n file, another file will be created in the i18n folder for the german language. Name it as i18n_DE.properties


Now, maintain the same field names in this particular file.
s3OrderColumnSales=Kundenauftrag
s3OrderColumnDelivery=Lieferstatus
s3OrderColumnOrder=Auftragsdatum
s3OrderColumnRequested=Wunschtermin
s3OderColumnAmount=Bestellbetrag
Now to see the output, in german language, just add DE instead of EN in the application url. Add ?sap-ui-language=DE after the url.
Suppose the default url is http://localhost:42067/demo_i18n/index.html just add ?sap-ui-language=DE. Now the url would be  http://localhost:42067/demo_i18n/index.html?sap-ui-language=DE
Output
 
Read more