Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to create multi-language feature for C++ program which would be similar to Android.
I have file language.xml and language-us.xml, if user's language is US then lang_variable is searching in language-us.xml, if didn't found then use keyword in language.xml . In code I would like to access lang-variables something like: R.string.lang_variable.
Language files can be not xml, i just want to make multi-language.
Thanks, for answer !
This is easily done by using lookup tables.
Any phrase that needs translation is assigned an ID value.
There is a table of ID vs. text for every language, can be as simple as an array of text.
Each supported language has an ID. There is one table of language ID vs. Language Table for every supported language.
So, first take the language ID and get the translation table for the given language.
Next, use the phrase or text ID to get the phrase from the language table.
This doesn't really have anything to do with the C++ language.
Also, use a character type that can support all required encodings, such as multibyte or Unicode.
Edit 1: Spreadsheets
We use a spreadsheet that contains the language ID (first column) and the translated text in different languages (each language is a separate column). We then have a custom application that converts the spreadsheet into appropriate tables (as discussed above).
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a Word document which is a template, and inside this document I whish to have some variable fields. Through my program I want to change these values on demand (e.g. calling Word and passing some parameters to it using a C++ program). I've searched a lot but so far I couldn't find good examples of that.
Microsoft Word has a proprietary file format which I imagine will be incredibly tricky to parse programmatically (i.e. by opening the file using an fstream).
If you are keen on using Microsoft products, your best bet may be to use Microsoft Access (a database manager), insert the data you want as a row in some database, and then create some formatted form which uses this data and generates a printable document for you. Here's a useful link: Create Form in Microsoft Access
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
What is the recommended way to scan Qt Desktop GUI source files for tr() translation strings and replace them in-place in the source code, with strings from another language?
Is this simply a job for a regex or is there something in Qt C++ source (for example, lupdate.exe) that could reasonably be used for modifying the source files? Or is there a more standard / idiomatic Qt way to do this?
Background:
Our source code has UI strings in Finnish. I would like them to be in English and then use qt translation to get Finnish.
Also I will then generate a new .ts file for the Finnish strings (that are currently in the C++ source files), but dealing with XML is easy in Qt anyway.
We've been building a desktop application with Qt for about 8 years. Along the way, it turned out that we should have used English as the source language (duh), and not Finnish. But we never had the time to do the switch, and now there are way too many strings to switch manually.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I have a program that I'm currently writing in English. In future, I would like to make the program multilingual, therefore I'm wondering what's the best option to do so. I thought about this two option for now:
Enable users to change language in settings;
Select the appropriate language while downloading;
With each option comes a problem:
A ton of code dedicated to displaying one message in different languages;
I will have to make many versions just to change the language of the displayed text;
Now my question is, which one of these options is more memory efficient and user friendly? Maybe neither of them are? Do you have any other option that is better than given two?
It is common to have an array or other structure, called something like strings, containing all the display strings your program will need. Instead of hardcoding messages into your program, you reference the array. To change language, you just alter the array.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
In the Java and JavaScript world json files are a standard way of storing complex data objects in files. Does C++ have its own standards in this matter too?
While I would disagree that storing JSON files is a "standard way" (esp. for Java), there are many different ways to achieve that in any language. It totally depends on your actual use case. You can write primitive values to files, key/value pairs of some sort, XML, JSON, YAML, write to a Database, send data to web services, ...
No, there is no standard way for generically storing data to files.
Not really. You could use static data (and have its constructor called, conceptually before main in an unspecified order).
You could also have a big literal string in your file -the raw string literal
feature of C++11 is handy- and have some code (e.g. a constructor which would accept a string encoded in JSON form) parse it.
They are just one way of storing data. Not "standard".
XML is another for example. All of these are available in C++ along with others
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I want to build a simple program that searches through a local database and returns a list of results. Essentially the program will be a searchable archive. This will be my first project of this type and I'm looking for some advice.
Fast reading of the database is important. Writing can be slow.
There will be at most a few thousand records, and most records will probably contain less than 3 kb in text.
Records should be flexible when it comes to their fields. Some records will have the field "abc", others will not. The number of fields per record may vary.
Should I simply write my data structures in C++, and then serialize them? Does it make sense to use an existing (lightweight) database framework? If so, can you recommend any that are free and easy to use and preferably written in modern C++?
My target platform is Window and I'm using the Visual Studio compiler.
Edit: the consensus is to use SQLite. Any recommendations as to which of the many SQlite C++ wrappers to use?
As commented by #Joachim, I would suggest SQLite. I have used it in C++ projects and it's straightforward to use. You basically put two files in your project sqlite3.c and sqlite3.h and then start coding to the interface (read the last paragraph of http://www.sqlite.org/selfcontained.html). You don't have to worry about configuring a database server. It's fast and lightweight. Read about transactions and SQLite if you need to speed some operations up.