In order to obtain translations via the Web, we need to make requests of an appropriate service. I selected Microsoft Translator for this project because it allows you to set up a free subscription to translate up to 2 million characters of text a month; using Google Translate instead would be similar, aside from the URLs used to communicate, but Google Translate does not, at the time of this writing, have any option for free or trial use through third-party programs.
The app assumes that all users of the app will use the same subscription information, so all translations done with TranslationBuddy will come out of the same 2,000,000 character per month service allowance. If you were launching this app as a product for wide use, you would presumably need to subscribe to a higher-capacity service plan and have a revenue model in place to support it, but for educational purposes, this basic account should be more than adequate.
Have a Windows Live ID created and available, either the one you already had or the one you create just for this project. They are freely available from Microsoft.
Open Corona and create a new scene-based project from the Corona splash screen as you did with the first two projects, called TranslationBuddy
. Create a new file called credentials.lua
in the project folder, open it, and enter the skeleton table that will hold the authorization information you're going to create:
return { id = [[]], secret = [[]], }
Creating a Microsoft Translator API application account is done through the Azure services marketplace:
CoronaHotshotProject3XXX
, replacing XXX
with your own initials; this must be unique across all applications registered on the marketplace, so it may be necessary to add your birth date or something else to the client ID to make it unique.TranslationBuddy
. The client secret field should be pre-populated; leave it alone. A redirect URL is required, but will not be used for this service; you can use a common URL such as https://example.com
.Mobile translation app
for the description, and click on CREATE. You should return to the Developers page, but your new name should now be visible under Registered Applications.credentials.lua
file so that the application can load it as needed.credentials.lua
that reads id = [[]]
, you'll need to type in the same client ID in between the pairs of brackets as follows:return {
id = [[CoronaHotshotProject3XXX]],
secret = [[]],
}
return {
id = [[CoronaHotshotProject3XXX]],
secret = [[a0B9c8D7e6+F5g4H3i2J1/]], -- not a real secret; paste in your own!
}
The double brackets indicate a Lua long string literal. The contents are converted into a string just as if you had used single quotes or double quotes, but nothing inside is a special character; everything is stored into the string contents exactly as you type it into the source. Long string literals can even span multiple lines and will include the new line characters as part of their content. They're good to use for strings that might have special character content, like XML markup. See section 2.1 of the Lua 5.1 manual for details.
Save and close credentials.lua
. You can save the details for the application on the developer site, and log out of Live if you're so inclined.
We registered an application with a shared communication secret that will allow us to authenticate our app as a legitimate user of the service. We stored the authentication information where we can easily load it into our app's Lua environment to incorporate it into our network requests. We'll be able to use this information in our app to obtain something like a cookie that we can include in our translation requests to show the service that they're genuine.
3.144.193.129