seastan / dragncards

Multiplayer online card game platform written in Elixir, Phoenix, and React. Drag and Drop provided by React-Beautiful-DND.
https://dragncards.com/
79 stars 41 forks source link

FORMAT_STRING function #85

Open morvael opened 3 months ago

morvael commented 3 months ago

A function that takes a format string and variable number of parameters, inserted at indexed positions would be a godsend. It could also be a way to achieve localization of internally created messages, if the format string would be a label id.

Examples:

1) ["FORMAT_STRING", "Second parameter is {1}, first parameter is {0}", "ABC", "DEF"] returns Second parameter is DEF, first parameter is ABC string.

2) ["FORMAT_STRING", "id:labelId", "ABC", "DEF"], system set to German language and the label as follows:

        "labelId": {
            "English": "Second parameter is {1}, first parameter is {0}",
            "German": "Der zweite Parameter ist {1}, der erste Parameter ist {0}"
        }

returns Der zweite Parameter ist DEF, der erste Parameter ist ABC string.

Parameters themselves could be also processed as labels but this isn't necessary as can be handled by some recursive use of FORMAT_STRING.

morvael commented 3 months ago

For easier understanding of the code it could be so that the English text is the label id: ["FORMAT_STRING", "Second parameter is {1}, first parameter is {0}", "ABC", "DEF"]

        "Second parameter is {1}, first parameter is {0}": {
            "German": "Der zweite Parameter ist {1}, der erste Parameter ist {0}"
        }