Source Code Analysis and Transformation to Aid Internationalization Support
Total Page:16
File Type:pdf, Size:1020Kb
Mestrado em Engenharia Informática Dissertação/Estágio - Relatório final 2017/2018 Source code analysis and transformation to aid internationalization support João Pedro Santos Batanete [email protected] July 2018 Orientador DEI: Ernesto Costa Orientador WIT: João Certo Tutor WIT: Carlos Mota Acknowledgements The present document marks the end of my tenure as Software Engi- neering student at the University of Coimbra. Firstly, I would like to thank both my supervisors and my tutor for all the feedback provided and all those times you pushed me in the right direction when I needed it. I have learned a lot from you, and I will continue to do my best towards improving myself as a professional in this field. I would also like to thank all the people at WIT-Software, who were always very friendly and welcoming to me, and provided invaluable feedback when I needed it. I would also like to thank my parents, sister and the rest of my family for all the support they gave me across all these years. Lastly, I would also like to thank my girlfriend for always cheering me up when I needed it the most and inspiring me to always try my best. Abstract With the widespread expansion of software markets, localization is becoming increasingly important. There is a pronounced correlation between application usage and availability in the home language. This creates the need to improve localization support processes in order to deliver applications more quickly and cost-effectively. In order to manage textual content, one commonly used approach is the use of key/value pairs to represent user interface text fragments with the values for each key, and for each target idiom being stored in a localization platform, which is used by the translating team to create the translations. Translators often need ”contextual” information when translating a given key in order to provide an acceptable translation for it. In order to achieve this, it is common to use screenshots of the application con- text (user interface) associated with each key that appears on-screen. The process of obtaining the associations is currently done manually, which is very time consuming and sometimes impractical for real-world applications where the number of keys is too large or the application’s user interface is too complex. The central objective of this internship is to create a tool that autom- atizes certain portions of the process by aiding the user in obtaining associations between the key/value pairs and the screenshots and up- loading them to a localization platform. This is achieved by changing application source code directly using static code analysis and trans- formation tools. The platforms supported initially will be Android and iOS but extensibility to other platforms is a primary goal. Keywords ”Android”, ”iOS”, ”Static code analysis”, ”Code transformation”, ”Lo- calization”, ”Internationalization”, ”ANTLR”, ”Key/value localiza- tion” Resumo Com a expansão dos mercados de software, a localização dos produ- tos está a tornar-se cada vez mais importante. Existe uma correlação pronunciada entre o sucesso das aplicações e a disponibilidade destas para o idioma local. Isto cria a necessidade de melhorar os processos de suporte à localização para possibilitar o desenvolvimento de apli- cações de forma mais eficiente em termos de custos e tempo. Para gerir conteúdo textual, uma abordagem comum é a utilização de pares chave/valor para representar os fragmentos de texto da user in- terface, com os valores correspondentes a cada chave e a cada idioma a serem armazenados numa plataforma de localização, que é utilizada pela equipa de tradução para criar as traduções. Os tradutores necessitam com frequência de informação ”contextual” para durante o processo de tradução de uma chave, de forma a con- seguirem disponibilizar uma tradução aceitável. Por forma a cumprir este requisito, é comum utilizar fotografias do contexto da aplicação (user interface) associadas com as chaves que aparecem no ecrã do dis- positivo. O processo de obtenção das associações é, neste momento, realizado de forma manual, o que o torna moroso e por vezes imprat- icável para aplicações em contexto real com um número de chaves demasiado grande, ou com uma user interface demasiado complexa. O objetivo central deste estágio é criar uma ferramenta que automatiza certas componentes do processo, auxiliando o utilizador na obtenção das associações entre os pares chave/valor e as fotografias e exportando- as para uma plataforma de localização. Isto é feito através da mod- ificação do código fonte de forma direta utilizando ferramentas de análise e transformação estática de código. As plataformas supor- tadas inicialmente irão ser Android e iOS, mas a extensibilidade a outras plataformas é um dos objetivos principais. Palavras-chave ”Android”, ”iOS”, ”Análise estática de código”, ”Transformação de código”, ”Localização”, ”Internationacionalização”, ”ANTLR”, ”Lo- calização com pares chave/valor” Contents 1 Introduction 1 1.1 Motivation ......................... 1 1.2 Objectives ......................... 2 1.3 Report structure ..................... 3 2 State of the art 5 2.1 Internationalization practices .............. 5 2.1.1 String encoding .................. 6 2.1.2 UI elements separation from source code .... 7 2.1.3 Key/Value approach ............... 8 2.1.4 Locale hierarchy ................. 8 2.2 Platform internationalization support .......... 9 2.2.1 Android ...................... 9 2.2.2 iOS ........................ 10 2.3 Localization (l10n) platforms and support tools .... 11 2.3.1 Pootle ....................... 12 2.3.2 Multilizer ..................... 13 2.3.3 Transifex ..................... 14 2.3.4 Text United .................... 15 2.3.5 WIT Software solution (i18n) .......... 16 2.3.6 Feature comparison and conclusions ...... 16 2.4 Code analysis and transformation tools ......... 17 2.4.1 Parser generators ................. 17 2.4.2 Static analysis tools ............... 20 2.4.3 Specialized code transformation tools ...... 21 2.4.4 Code transformation tool analysis ........ 24 3 Project management 27 3.1 Software development lifecycle .............. 27 3.2 First semester tasks .................... 28 3.2.1 Completion assessment .............. 28 3.3 Second semester tasks .................. 28 3.3.1 Completion assessment .............. 29 3.4 Success metrics ...................... 29 4 Requirements 31 4.1 Functional ......................... 31 4.2 Non-functional ...................... 33 5 Architecture 35 5.1 Transformation module .................. 36 5.1.1 Generic transformations ............. 37 5.1.2 Platform-specific transformations ........ 37 5.2 Modified application project ............... 38 5.3 Platform-specific libraries ................ 38 5.4 Web module ........................ 39 5.4.1 Web interface ................... 39 5.4.2 HTTP interface .................. 40 5.4.3 Persistence submodule .............. 41 5.5 Export module(i18n) ................... 42 5.6 Translation platform(i18n) ................ 43 6 Code analysis and transformation 44 6.1 Transformation patterns ................. 44 6.2 Android (Java) ...................... 46 6.2.1 Other transformations .............. 46 6.3 iOS (Objective-C) ..................... 46 6.3.1 Other transformations .............. 48 6.4 String ambiguity handling ................ 49 6.5 Prevention of repeated string reports .......... 50 7 Testing and evaluation 52 7.1 Unit tests ......................... 52 7.1.1 Web module ................... 52 7.1.2 Transform module ................ 53 7.1.3 Support libraries ................. 57 7.2 Integration tests ..................... 62 7.3 Usability tests ....................... 62 7.4 String coverage tests ................... 63 8 Conclusion 65 8.1 Work done ......................... 65 8.2 Future work ........................ 66 8.2.1 Web module ................... 66 8.2.2 Transformation module and support libraries . 66 8.3 Final thoughts ...................... 66 Appendices 67 A Internship context 67 B Tests performed on the code analysis and transforma- tion tools 68 B.1 Test performed ...................... 68 B.2 ANTLR procedures .................... 68 B.3 CodeWorker procedures ................. 71 C Implementation details 76 C.1 Android use cases ..................... 77 C.2 iOS use cases ....................... 81 D REST API documentation 82 E First semester Gantt chart 84 F Second semester Gantt chart 85 G Weekly tasks 86 G.1 First semester ....................... 86 G.2 Second semester ...................... 89 List of Figures 1 Character representations in different Unicode encod- ings. [36] .......................... 7 2 Localized resources on the .NET platform. [35] ..... 7 3 Example of a possible key/value correspondence. ... 8 4 Multi-language Android Studio project values folder. [8] 10 5 Retrieving a string from Java code. [21] ......... 10 6 Example Xcode project translated into several idioms. [43] ............................. 11 7 l10n support tool - Pootle. ................ 12 8 l10n support tool - Multilizer. .............. 13 9 l10n support tool - Transifex. .............. 14 10 l10n support tool - Text United. ............. 15 11 Code analysis and transformation tool - Bison. ..... 18 12 Code analysis and transformation tool - ANTLR. ... 19 13 Code analysis and transformation tool - Facebook Infer. 21 14 DMS Software Re-engineering Toolkit - company logo (Semantic Designs). .................... 22 15 Overall system architecture. ............... 35 16 SQLite