PrismarineJS / flying-squid

Create Minecraft servers with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/flying-squid/
MIT License
540 stars 101 forks source link

Localization #413

Open somucheffort opened 4 years ago

somucheffort commented 4 years ago

Well, I've added locale.js plugin (PR #414), so I think commands and other things need to be localized.

Currently, addString looks like this:

serv.locales.addString('lang', 'stringName', 'stringValue') // also stringName needs to be parsed like stringName/under or stringName:under, etc.
ghost commented 4 years ago

Would it make sense to use an actual service for this where users can submit translations and localizations?

rom1504 commented 4 years ago

Mojang already provides all the translation, we can just use them.

What are you trying to do here ?

somucheffort commented 4 years ago

Mojang provides translations for minecraft commands but contributors can make own plugins with own localization

somucheffort commented 4 years ago

But flying-squid doesn't have any localization now. So it kinda make sense..?

somucheffort commented 4 years ago

All objects (needs to find langs): .minecraft/assets/indexes, Searching in .minecraft/assets/objects

lastuniverse commented 3 years ago

Sorry. Can my module help solve this problem? https://www.npmjs.com/package/msg-localize

Unfortunately, I got into the essence of the problem very superficially. Perhaps I could remake it so that it solves the task, but for this I need to explain the essence of the task in a little more detail)

lastuniverse commented 3 years ago

task

serv.locales.setStringLang(lang, path, value)
serv.locales.setString(path, values)
serv.locales.getString(lang, path) || serv.localeString(lang, path)
player.localeString(path)

Your еxamples

Set string in one lang

serv.locales.setStringLang('en_us', 'example.path', 'Hello!')

Set string to multiple langs

serv.locales.setString('example.path.multiple', {
  en_US: 'Multiple languages',
  ru_RU: 'Несколько языков'
})

Get localized string

serv.info(serv.localeString('en_US', 'example.path.multiple')) // return 'Multiple languages'

Examples with msg-localize

Set string in one lang

in file path/to/lang/folder/en_us.json

{
    "example": {
        "path": "Hello!"
    }
}

Set string to multiple langs

in file path/to/lang/folder/en_us.json

{
    "example": {
        "path": "Hello!"
    }
}

in file path/to/lang/folder/fr_fr.hjson (hjson - json with comments)

{
    "example": {
        // "Hello" in French
        "path": "Bonjour!"
    }
}

in file path/to/lang/folder/ru_ru.json

{
    "example": {
        "path": "Привет!"
    }
}

in your js code

...
const Messages = require('msg-localize');
serv.locales = new Messages('/path/to/lang/folder/','en_us'); // 'en_US' - sets default language (English)
serv.locales.langs = serv.locales.messages; // an associative array, in which the keys are 'en_us', etc. and the values ​​are the contents of the localization files `path/to/lang/folder/en_us.json`, etc.
serv.locales.getString = (lang,path)=>serv.locales.getMessage(path,lang);
...
player.localeString = (path)=>{
    serv.locales.getMessage(path, player.lang ) // Instead of player.lang, you need to use player.that_contains_the_language_code
}
...

Get localized string

in your js code

...
serv.locales.getString('example.path'); // return message in default language (English): 'Hello!'
serv.locales.getString('fr_fr', 'example.path'); // return message in French: 'Bonjour!'
serv.locales.getString('ru_ru', 'example.path'); // return message in Russian: 'Привет!'
serv.locales.getString('de_de', 'example.path') ;// return message in default language (English): 'Hello!'
...
...
player.localeString('example.path') // will return a greeting in the user's language (if there is a localization file for him) or in the default language
...

!!!If the license of the module confuses, then I can change it to any other.!!!

rom1504 commented 3 years ago

What redcarti is trying to do here is use the localized messages provided my mojang. It might be useful to keep the ability to localize other messages though yes

On Tue, Nov 3, 2020, 12:17 lastuniverse notifications@github.com wrote:

task

serv.locales.setStringLang(lang, path, value) serv.locales.setString(path, values) serv.locales.getString(lang, path) || serv.localeString(lang, path) player.localeString(path)

Your еxamples Set string in one lang

serv.locales.setStringLang('en_us', 'example.path', 'Hello!')

Set string to multiple langs

serv.locales.setString('example.path.multiple', {

en_US: 'Multiple languages',

ru_RU: 'Несколько языков' })

Get localized string

serv.info(serv.localeString('en_US', 'example.path.multiple')) // return 'Multiple languages'

Examples with msg-localize https://www.npmjs.com/package/msg-localize Set string in one lang

in file path/to/lang/folder/en_us.json

{

"example": {

    "path": "Hello!"

}

}

Set string to multiple langs

in file path/to/lang/folder/en_us.json

{

"example": {

    "path": "Hello!"

}

}

in file path/to/lang/folder/fr_fr.json

{

"example": {

    "path": "Bonjour!"

}

}

in file path/to/lang/folder/ru_ru.json

{

"example": {

    "path": "Привет!"

}

}

in your js code

... const Messages = require('msg-localize'); serv.locales = new Messages("path/to/lang/folder/","en_us"); // "en_US" - sets default language

...

Get localized string

in your js code

... serv.locales.getMessage('example.path'); // return message in default language: "Hello!" serv.locales.getMessage('example.path', "fr_fr"); // return message in french: "Bonjour!" serv.locales.getMessage('example.path', "ru_ru"); // return message in russian: "Привет!" serv.locales.getMessage('example.path', "de_de") ;// return message in default language: "Hello!"

...

!!!If the license of the module confuses, then I can change it to any other.!!!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/flying-squid/issues/413#issuecomment-721055157, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR437VK3QX2Z4Q3IBSMAJLSN7RFZANCNFSM4OOXC3JA .

lastuniverse commented 3 years ago

hmm, now I understand the essence of the problem. But wouldn't it have been easier to just write the mojang localization file parsers in some universal format? This can work at build stage and will allow you to standardize the localization of your server implementation. It would also eliminate the need to support different versions of mojang localization right in the server's running code.

somucheffort commented 3 years ago

This issue is related for #414, where I made a locale manager. But I didn't know much about JSON Chat, so #414 now is closed.

somucheffort commented 3 years ago

I didn't think much about user localization, but with JSON Chat it's not possible, you need to use your manager. I have gist of my LocaleManager class, so you can use it to localize your messages

lastuniverse commented 3 years ago

Ok.

somucheffort commented 3 years ago

btw you can also use your example, msg-localize

lastuniverse commented 3 years ago

yes ))))

lastuniverse commented 3 years ago

msg-localize I wrote for localizing telegrams and discord bots, but it's versatile enough to be used anywhere)