C
C#16mo ago
FridgePirate

❔ How can I read data from file called lang.json

C#
using System;
using System.Collections.Generic;
using CitizenFX.Core;
using Newtonsoft.Json;
using static CitizenFX.Core.Native.API;

namespace QBCore_family
{
public class FamilyServer : BaseScript
{
public FamilyServer()
{
RegisterCommand("setmother", new Action<int, List<object>, string>(SetMotherCommand), false);
}

private void SetMotherCommand(int source, List<object> args, string raw)
{
TriggerClientEvent("chat:addMessage", new
{
color = new[] { 255, 0, 0 },
args = new[] { "[CarSpawner]", "Heller!" }
});

}
}
}
C#
using System;
using System.Collections.Generic;
using CitizenFX.Core;
using Newtonsoft.Json;
using static CitizenFX.Core.Native.API;

namespace QBCore_family
{
public class FamilyServer : BaseScript
{
public FamilyServer()
{
RegisterCommand("setmother", new Action<int, List<object>, string>(SetMotherCommand), false);
}

private void SetMotherCommand(int source, List<object> args, string raw)
{
TriggerClientEvent("chat:addMessage", new
{
color = new[] { 255, 0, 0 },
args = new[] { "[CarSpawner]", "Heller!" }
});

}
}
}
I want to replace "Heller!" with "welcome" from:
Config = {}

Config.defaultlocale = "en" // default locale

Config.Locale = {
"en": {
"welcome": "Welcome to the server!",
"farewell": "Goodbye, see you later!",
"player_join": "{player} has joined the server."
},
"es": {
"welcome": "¡Bienvenido al servidor!",
"farewell": "¡Adiós, hasta luego!",
"player_join": "{player} se ha unido al servidor."
}
}
Config = {}

Config.defaultlocale = "en" // default locale

Config.Locale = {
"en": {
"welcome": "Welcome to the server!",
"farewell": "Goodbye, see you later!",
"player_join": "{player} has joined the server."
},
"es": {
"welcome": "¡Bienvenido al servidor!",
"farewell": "¡Adiós, hasta luego!",
"player_join": "{player} se ha unido al servidor."
}
}
5 Replies
Angius
Angius16mo ago
1. Read the file with, say, File.ReadAllTextAsync() 2. Deserialize with System.Text.Json's JsonSerializer.Deserialize<Class>() 3. ??? 4. PROFIT
FridgePirate
FridgePirateOP16mo ago
Thank you Mr./Mrs. Z. I managed to build a solution and it works!
Angius
Angius16mo ago
Nice
✿ Scarlet ✿
✿ Scarlet ✿16mo ago
I got lost at 3. unclear instructions
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server