Learning programming seems to be a trending area of study among in the field of localization. Computers offer us the means to connect with every aspect of our business and optimize our workflows, but not everyone is taking full advantage of what they have to offer. This is why learning to code has been a critical part of my learning and continual professional development in the field.
Learning to program with Python
Programming with Python has one of the lowest barriers to entry to those who have no background in computer science like myself. I was able to teach myself enough Python to write an automation script that helped me quickly execute the mundane and tedious task of registering for classes, and ironically helped me register for my first Python class, Intro to Programming with Python. Here is a very early demo video of the automation script working:
Localization Automation with Python
The excitement of being able to automate such a boring task using programming inspired me to pursue learning and exploring more on my own. So for my final practicum project I decided to team up with a few of my colleagues to figure out a way to automate a localization process that prepares files for translation.
The task we decided to look at was localizing JavaScript for applications and websites, a process that involves finding the strings of text that need to be taken out and prepared for translation, and then imported back to the source. This process sounds complicated but there are a few methods, known as internationalization frameworks, that can make extracting and inserting translated strings an efficient process. We wanted to take this process further by using Python’s powerful automation capabilities to streamline the workflow.
Part of this project grew out of inspiration from a file automation script I made for automating project management tasks. The main component I drew upon was utilizing Pathlib to handle file paths as objects to manipulate them cleanly and efficiently. I highly recommend looking into this module for use in scripting with Python as it makes working with folders and paths very efficient. Here is a preview of the script I wrote to help count files using pathlib:
The main project libraries we chose for this program were Beautiful Soup which allows us to take in HTML files for analysis. We first started with HTML files and then used our script to make a copy of the file and extract all of the strings. Then the program creates a .js file that has the source string and an empty string that will be filled with the translation when it gets uploaded to a CAT tool and translated by a linguist. This way, files can be easily re imported and used in the main program.
Below is a picture of the first few functions of our program. The wrapStrings function takes in an html file and makes a new file with all the strings wrapped in our _( ) 24 ways function.
The next function in the script copies the entire folder,essentially making a backup for your files in case anything goes wrong or you want to keep the original version of the files before sending them off for translation
The last part of the program looks for all html files in the folder and calls our getStrings and wrapStrings functions to extract and prepare the files for translation in a CAT tool. I hope you enjoyed reading about this project and if you are interested in more details, feel free to check out a 10 min video we made on the entire project including where we think the project can go from here in case anyone is interested in picking up where we left off. Our project files are hosted for you to download if you want and feel free to reach out if you have any questions.
Link to Python Research Video: