Wednesday, February 8

i10n and Plural Forms

Have you know that some languages have more than two plural forms?
I never notice this fact and was blind to it but the creators of gettext l10n system were not.

What I thought was the general rule?

Most English speaking people are used to the fact that ordinal things are either single or plural but even in English when you count centuries you say 1st, 2nd, 3rd, 4th, 5th and so on. So even in English you sometime need to have special cases when converting pure numeric values to human readable text.

I was surprised to see that Arabic has 6 plural forms and the rules of when to use each were not plain at all.

What does this means technically?

When using gettext functions, that's include C but also PHP, Python and other languages you have the l10n function _n which accept the single form and the plural form.
Because each language can have very different rules for plurals each po file has a field name Plural-Forms that define an expression such as nplurals=2; plural=(n > 1);

This expression is built from two parts: nplurals is the number of plural forms supported by the language. plural is C like expression with input n and output of the index of the plural l10n message to use.

Checkout a list of such expressions for languages.

Conclusion

Next time you do l10n remember to use plurals and not just add S when n > 1 :)

Sunday, December 18

React on Google App Engine

I've decide to build an app using React on the client side and Python on App Engine on the server-side.
Search the web for a starter project for that configuration I found only out-of-date solutions, so I've built my own.

tl;dr

How to run React on App Engine?

I've decide to use create-react-app and I've create the required npm scripts to run it locally and deploy it to App Engine.

npm start

Use this command to run both Webpack dev-server and App Engine dev-server for development. Both of the dev-servers support hot-reload so you can use your favorite text editor to edit both React and App Engine code, save it and you have the latest code already in the browser without refresh anything.

npm run deploy

Use this command to deploy the app to App Engine. I'm reading configuration from package.json under "appEngine" to decide which app to push to.

For all the other details page see the github readme.

Friday, December 18

Replacement for Mailbox

Outlook.

I wasn't going for Outlook when I got the news that Mailbox is shutting down.
I've been using Mailbox on my iPhone4 and continue to do so when I've move to OnePlus One.
To my surprise when I search the Play Store for mail the first result was Outlook. I've not use outlook for over 10 years, and I never looked back.

The reason I'm not using Gmail nor Inbox is that they do not support multiple accounts in one view. I have both my personal and work email, both hosted by Google, and I don't want to keep switching between the two accounts.

Outlook is fast, clear and support multiple accounts in one view.

Saturday, August 22

Using MPS to Keep Several SDKs Up-To-Date

It has been very long time since my last post.
This time I'll like to introduce an idea, not a complete solution.
I'm working in a team responsible for keeping 5 SDKs in ship-shape and up-to-date. Each SDK is written in different platform and also different language. To name a few iOS with Obj-C, Android with Java, Unity with C#, Cordova with JavaScript and Adobe AIR with ActionScript3.

Maintain and develop all of those SDKs manually is never-ending work. Even if we'll scale the team and have a team per SDK it will still be hard to maintain because then fragmentation of the different SDKs will happen even more frequently than one team.

After research several directions I've decide to concentrate on using JetBrains Meta Programming System (MPS) to create one meta-language from which we will be able to generate all the different SDKs source code.

It is important to note I'm not trying to generate the entire SDK in each platform, only the parts that are not platform specific which in our case are also the parts that change frequently.

This diagram show the flow

In future posts I'll describe each of those steps:

  1. Building MPS counterpart of each language
  2. Building TextGen for each language
  3. Building X language (I haven't found a name yet)
  4. Building model-to-model transformation for each language
  5. Build scripts to combine each SDK platform-specific part with the auto-generated part
  6. Hidden parts that I'm not able to see yet (please leave a comment if you do)

Tuesday, August 5

ProtoBuf in Unity3D

Recently I needed to add two way communication to Unity3D plugin I worked on. We decide to use plain-old-sockets and use Protocol Buffers to serialize and deserialize the messages.
We already had the proto file that define the messages and the server side is already written so all I needed was ProtoBuf implementation for .NET. The main problem is that most C# libraries for ProtoBuf either use attributes and not proto files or they use reflection which is not supported in Ahead-Of-Time (AOT) environment like Unity3D on iOS.

After some research I decide to use ProtoBuf C# Code Generator project by Peter Hultqvist. The main difference between this and other ProtoBuf implementations is that this one create C# code that does not use reflection and does not depend on binary libraries. It generate 3 files:

  1. The clean messages file that contain only the properties of each message
  2. The somewhat messy serialization/deserialization counterpart of each message.
  3. Helper classes
I use this library on Mac OS X with mono and it run without a problem. It generate clean code that you can easily read.

The few minor issues I did find were quickly (2 hours) fixed by Peter.

Things to note

Api Compatibility Level

One important notice for Unity3D developers: because the current generated code uses InvalidDataException which is not part of .NET 2.0 subset. If you don't to the following change the project will fail when building iOS XCode project with error message that not explain what is wrong.
You must do the following before exporting to iOS XCode project:
  1. Open Build Settings window
  2. Select iOS
  3. Click Player Settings... button
  4. Under Optimization section change Api Compatibility Level to .NET 2.0

Reading Message

If you want to read message from a socket you will need to wrap your Socket instance with NetworkStream and then wrap that with SilentOrbit.ProtocolBuffers.StreamRead. This might be confusing because there is already StreamReader class in .NET, I point that to Peter and I'm sure he will find other name.
If you don't wrap your NetworkStream with StreamRead you'll find that the underlying code uses Position property which is off course not available in NetworkStream.

Using Socket in Unity3D without Pro License

Recently I needed to add to our Unity3D plugin the ability to talk to another application via sockets. I'm a long time .NET developer and sockets is peace of cake to use. The problem start when I test the application on iPad device. During the building of XCode project from Unity I got the exception:

Error building Player: SystemException: System.Net.Sockets are supported only on Unity iOS Pro. Referenced from assembly 'Assembly-CSharp'.

As it turns out Unity3D AOT compiler check and fail if any of your script or the plugins you have uses System.Net.Sockets namespace without having pro license.

The solution is to use a plugin call Good Old Sockets which you can find right in the Assets Store of Unity3D. This library require only to change the namespace you are using from System.Net.Sockets to LostPolygon.System.Net.Sockets. The price is 25$ at this time and their license is very open, you can use and distribute this library without extra cost.

I had very quick response for support from LostPolygon both in mail and in Skype.

Saturday, March 22

Generate PDF with Sphinx Documentation System

Documentation

One of the most important things in any project is documentation, yet it is usually the last thing if it is done at all.

I've recently change jobs and in the new company we create SDKs for different platform and languages. We are lean and fast and do a lot of changes quickly but we realize we better get our documentation abilities agile as well as our development skills.

What is Sphinx?

After evaluating several documentation tools I've found Sphinx. This is the tool used for Python documentation. The reason it looks best for me is that it is a mature project, it has a notion of version which is important for documentation as it is important for the software itself. It has many extensions that are not required for me now but I'm sure will come in handy later.

Output to HTML

The first and most important requirement is that the tool will be able to output HTML based documentation. This is because we plan to have each specific platform's SDK created in it native tool and use HTML as the one unified languages to connect them all together (thank you hyperlink).
If you follow the quick-start application of sphinx all you need to do to create HTML docs is 

make html

Output to PDF

This is not a must but it will be nice to be able to create PDF documentation both for download and in-browser reading. The problem is that when I run make latexpdf I got this error:

make[1]: pdflatex: No such file or directory

After google it for a bit I was able to find a post about how to generate PDF  using Sphinx. From there I was able to find the line after pdflatex command as follows:
This is pdfTeXk, Version 3.141592-1.40.3 (Web2C 7.5.6)
Using this I was able to find MacTeX-2013 Distribution which is Mac package for TeX tools. The problem is that the main download is 2.2GB download but a few clicks away is Smaller packages for only the essential tools.