Sk
Hello my friends I am from India I need online work someone please tell me
Devil Within
Sk
Abbasi
Seems https://cppquiz.org/ is more constructive.
ж
va bene così
Ludovic 'Archivist'
Pavel
That goes too much into OT, but I want to add my 2 cents. I feel like getting through the hiring process is a lot like dating.
You need to look interesting as a hire candidate to give a good first impression. They shouldn't ask themselves a question "Why is he unemployed/can't find a job right away? Is there something off?"
Vlad
Vlad
You having a job and not looking even increases chances of getting offers on there
Vlad
Rose
Reported Sarah Vine [6641300082] to admins.
Cayetano
Hi guys!
I'm wondering if I should create from scratch a i18n module to translate the string into the app or there are any library or Github repository that could make easy the translations.
It would be amazing if the translations will be stored in JSON files
Any clue guys?
harmony5 🇺🇳 ⌤
Cayetano
Cayetano
Well, it is great but is not exactly that I would like...
Cayetano
I'm looking for a library that let to load a json file with translations like
{
"moon": "Moon",
"sun": "Sun",
"animals": {
"cat": "Cat"
}
}
And using like translate('moon') giving the translation in the locale settings, in this case en_US, and it should be 'Moon', but if you change your locale to es_ES it would be 'Luna' according with the file named es_ES.json, of course
Cayetano
It would be great to provide a way to manage the fallback, but if not, I can handle it
Cayetano
I have using https://github.com/stefandevai/i18n_keyval/tree/main but I can find any way to load the file, that library was created thinking to have multiple translations... And I don't know if it will be the best approach for me
Abbasi
Are you by any chance going to provide an application UI with multiple languages for the user to choose based on their preference?
Sarah
Happy new month
Cayetano
But I was thinking about how to implement and what I really need and, to be honest, I'm thinking about implementing the module by myself, although I don't know if it will be a good idea
Abbasi
I did something similar in my last role (in an automotive project for a German company)
The GUI library we used was Dear ImGui however.
I used a std::map per language with fixed keys and different values, in one of headers.
Cayetano
Ludovic 'Archivist'
C++26 has been frozen. Details should be on cppreference in a couple of weeks
Cayetano
Cayetano
Cayetano
🙏 thanks
Ludovic 'Archivist'
Could you write the Url, please?
You will have to wait for it to be published on the ISO website, it costs about $150 to buy a copy when it does
Vlad
I aint gonna say nothing that you can read drafts for free
Vlad
Vlad
It's literally mapped on an array 1-to-1
Abbasi
Not sure what you mean by "basic enum", "retarded" and "1-to-1".
Using std::map we can achieve unique keys and fast look-up.
While keys are unique, values can be the same which can happen for languages too.
What other method would you go for instead?
Cayetano
Thanks for ideas, I have thought something like this:
std::unordered_map<std::string, std::unordered_map<std::string, std::string>>;
What do you think about it?
Vlad
Vlad
Hence the index of array will map the KEY exactly
Abbasi
Vlad
Abbasi
We use an enum class not enum
Ludovic 'Archivist'
Vlad
Unless your enum has non sequencial values you should not use std::map
Vlad
Furthermore its mapped using arrays in C all the time
Ludovic 'Archivist'
Cayetano
Regarding the list of supported languages, I will store as two parts, one, as #define to store the identifier, and another as std::map to store the relationship between the #define and the string... Some like this:
#define SPANISH_ARGENTINA "es_AR"
#define SPANISH_BOLIVIA "es_BO"
...
...
and
inline std::map<std::string, std::string> languages = {
{"es_AR", "Spanish (Argentina)"},
{"es_BO", "Spanish (Bolivia)"},
....
};
Vlad
Vlad
Or es_AR is a part of the programming interface?
Cayetano
Well, not convert, but I will need the relationship to show to the user a dropdown where he can select the user (name) and return the code
Vlad
Vlad
enum class lang {...};
std::string lang_short[lang::count];
std::string lang_description[lang::count];
...
const auto& lang_code = lang_short[(int)lang::es_AR];
const auto& lang_desc = lang_description[(int)lang::es_AR];
Vlad
Something like this
Vlad
You may make arrays const as well
Ludovic 'Archivist'
Vlad
Vlad
Good enough, and less annoying to use
Ludovic 'Archivist'
Or char[6]
char[6] would do twice the cache eviction of uint32_t
Abbasi
Hence the index of array will map the KEY exactly
In
enum class Key { One, Two };
int main() {
const std::map<Key, const char *> englishLan{{Key::One, "one"},
{Key::Two, "two"}};
std::map<Key, const char *> lan = englishLan;
Something like lan[0] or lan[One] seems not possible.
lan[Key::one] works fine.
Perhaphs I didn't get what you meant.
Vlad
Vlad
Duh
Ludovic 'Archivist'
Cayetano
@Abbasi_dev Are you sure that your solution is more efficient than mine?
@QNeko Could you explain a little bit more your suggestion, please?
Vlad
Vlad
I get static cast for pointers and references though
Vlad
Ludovic 'Archivist'
That is the main difference
Ludovic 'Archivist'
Abbasi
Vlad