Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translation and formatting expressions #319

Closed

Conversation

victorlevasseur
Copy link
Contributor

Native game only implementation
Do not merge now, opened for discussions.

This PR adds two features.

The features

String formatting

A string expression provides a string formatting feature with a simple and easier syntax than the C syntax.

For example:

Format("{0} is {2} but the parser still need some {1}", "Formatting", "work!", "cool")

I implemented a small parser for this syntax, tell me how I can improve/optimize it. It uses std::string
internally to avoid unnecessary UTF8 iterating as the only relevant characters are {, } and the numbers.

To make this string expression possible, I added a new type to the parameters: ````variadic```. The kind of parameter obviously only works if placed at the end of an expression/action/condition parameters list. The extraInfo field is used to determine the type of the variadic parameter (only one type, either "string" or "expression", so this is more limited than the C++ parameters packs).

These parameters accepts from 0 to an infinity of values. The editors have not been updated to allow assisted insertion of such parameters making them impossible to use currently in conditions and actions. However, the expression parser has been updated not to throw error messages due to the parameter count with variadics.

Translation

Using the _("something here") string expression, strings can be translated. A button has been added to the "Project" ribbon to generate a .pot file from all marked strings and an action is provided to load a translation from a .mo file.

The .mo parsing is done with a simple "parser" I wrote too.

Here is the documentation draft of the translation feature: http://wiki.compilgames.net/doku.php/gdevelop/documentation/game_translation

Discussion

Some points I would like to discuss:

  • this: ExpressionParser in external events #318
  • The formatting parser is working but I think it can be largely optimized, ideas ?
  • Javascript implementation
  • GUI for variadic parameters in expressions editors
  • GUI for variadic parameters in instruction editor
  • Allowing (in the conventional way) .mo files to be added in the project resources ("Image bank").

@victorlevasseur victorlevasseur added ✨ enhancement Need a game/precise steps to reproduce the issue The bug is hard to reproduce. More detailed steps or investigation is required. labels Nov 28, 2016
@4ian
Copy link
Owner

4ian commented Nov 30, 2016

That's a pretty big project you have there :) Let's try to keep things simple, in particular for the Javascript engines where the translations could be a "simple" JSON file. In most cases, JS games will run in an environment (browser, Cocos2d-JS, Electron sometimes) that do not provide access to external files (browser in particular), so the translations will have to be built in.

@victorlevasseur
Copy link
Contributor Author

If we explicitly allow adding other files to the "image" bank. Then, we can easily add builtin .mo files to projects, solving the problem for Javascript projects. Then, I chose the gettext format so that we don't have to bother with the translation editing tool as there are many already developped.

@4ian
Copy link
Owner

4ian commented Nov 30, 2016

.mo files are in a binary format so I'm not totally sure we can use it in Javascript (in Node.js there are surely ways to do it, but not in "Vanilla JS" in browsers). But some people already created workaround it seems: https://github.com/mikeedwards/po2json

@4ian
Copy link
Owner

4ian commented Nov 30, 2016

Sure it's a good idea to stick to existing formats :)

@victorlevasseur
Copy link
Contributor Author

If we allow to embed the .mo files (either by putting them in the image manager or, like the sound, by automatically put them into the compiled project), we can load them using the ResourcesLoader from pixi or cc.Loader from Cocos2D. Then, we can get a byte array and I can, as I made for the C++ implementation, write a simple parser for the .mo file.

Add rawfile parameter type allowing the user to select a file with custom
filters (as extra info)
@victorlevasseur
Copy link
Contributor Author

How can I get the file in a synchronous way without forcing it from being preloaded? (and is there a way to preload a file without asking the user to add the file to the "image bank"?)

@4ian
Copy link
Owner

4ian commented Dec 27, 2016

What is the issue with the rawfile parameter that you've added. What is your problem precisely?

@victorlevasseur
Copy link
Contributor Author

victorlevasseur commented Dec 27, 2016 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement Need a game/precise steps to reproduce the issue The bug is hard to reproduce. More detailed steps or investigation is required.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants