C
C#12mo 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
Angius12mo ago
1. Read the file with, say, File.ReadAllTextAsync() 2. Deserialize with System.Text.Json's JsonSerializer.Deserialize<Class>() 3. ??? 4. PROFIT
FridgePirate
FridgePirate12mo ago
Thank you Mr./Mrs. Z. I managed to build a solution and it works!
Angius
Angius12mo ago
Nice
a coding witch
a coding witch12mo ago
I got lost at 3. unclear instructions
Accord
Accord12mo 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
More Posts
✅ ByBit .NetI have a problem with bybit.net, when I try to get acc balance it successfully sends me data but whe❔ C# Web browser change tabs = index 0 is out of range exception.I am making a web browser and every time I change the selected tab, it gives me an index 0 is out of❔ Change default behaviour of .NET Web API Validation ErrorsHi does anyone know how I can override the default problem details/validation error response .net gi❔ How would you refactor something like this? Is there a pattern that could help me?Is there a way to clean something like this up? I've got a lot of evaluations to perform based on a ❔ C# library usable from pythonI was wondering how to do this, and stumbled upon https://stackoverflow.com/a/29854281 which answere❔ Is there a pattern for having a single collection of different object types?This is my sample code https://dotnetfiddle.net/ffV3vY I have a WorkflowCommand a ScheduledWorkflowC❔ How to create WPF installer?Hello, I want to create installer.exe file using WPF, so i have custom GUI. I want to copy files froASK beginnerI'm confused about it. Could someone please explain it? Should I check mark it? or when I'll mark ❔ ✅ Error MSB4018 : The "ResolvePackageAssets" task failed unexpectedly. When building.Full Stacktrace: Use build tool: C:\Program Files\dotnet\sdk\8.0.100-preview.5.23303.2\MSBuild.dll ❔ Raw Websockets, ref alternative in async programming```cs public async Task HandleUpgrade() { if (!HttpContext.WebSockets.IsWebSocketReques