Creating the account

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.

Getting ready

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 = [[]],
}

Getting on with it

Creating a Microsoft Translator API application account is done through the Azure services marketplace:

  1. Start by directing your web browser to https://datamarket.azure.com/dataset/bing/microsofttranslator and let the page load. Price listings should appear on the right-hand side of the page; scroll down past the alarmingly large numbers at the beginning and locate the bottom entry in the list, which should say SIGN UP rather than BUY; click on SIGN UP. You may be required to sign in with your Windows Live ID at this point.
  2. If you have not used your Live ID to obtain services through the Azure Marketplace before, you may need to enter some information about yourself in order to proceed. Once you have completed the form fields and selected CONTINUE, you should be presented with the Terms of Use for the Microsoft Windows Azure Marketplace. Feel free to read them over; if you cannot comply with them, move on to the next project. Check I accept the Terms of Use and click on REGISTER when you are ready to proceed.
  3. At this point, you are nearly done signing up for the Translator service access. Check I have read and agree to the above publisher's Offer Terms and Privacy Policy and click on SIGN UP. This should take you to a purchase receipt page.
  4. Now that you have an allowance for the service, you need to create a secret key and client ID that the app will use to identify itself to the service in order to have its requests accepted. Go to https://datamarket.azure.com/developer/applications/ in your browser and find the section towards the bottom of the page entitled Registered Applications. Unless you have used this Live ID for other development work, it will probably say "You do not have any registered applications." Click on the REGISTER button.
  5. A form appears requesting identifying information about your application. For the client ID, enter 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.
  6. For the name, enter 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.
  7. Enter 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.
  8. Follow the Edit link at the right-hand side of the screen next to it. This reopens the form you used to register the application. We'll enter the required information into the credentials.lua file so that the application can load it as needed.
  9. The client ID is permanent and can't be selected, so on the line in 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 = [[]],
    }
  10. The secret is much more complicated and easy to mistype, but you can also select and copy the contents of the text box and paste them into the brackets (be careful to select all the characters in the text box, and nothing else on the page):
    return {
      id = [[CoronaHotshotProject3XXX]],
      secret = [[a0B9c8D7e6+F5g4H3i2J1/]], -- not a real secret; paste in your own!
    }

Note

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.

What did we do?

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.

What else do I need to know?

Treat your application as secret and client ID as confidential information! If they become public, the odds are good that some stranger in another country will start using them to freeload off your Azure subscription and use up your service allowance for himself/herself.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.193.129