59 lines
2.1 KiB
C#
59 lines
2.1 KiB
C#
using System;
|
|
using System.IO;
|
|
using Avalonia;
|
|
using Avalonia.Platform;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Ocarina2.Models;
|
|
|
|
public class Language
|
|
{
|
|
public string Code;
|
|
public readonly string MenuFile;
|
|
public readonly string MenuOpen;
|
|
public readonly string MenuExit;
|
|
public readonly string Music;
|
|
public readonly string NoMusic;
|
|
public readonly string RPSong;
|
|
public readonly string RPArtist;
|
|
public readonly string RPIconText;
|
|
|
|
public Language(string code, string menuFile, string menuOpen, string menuExit, string music, string noMusic, string rpSong, string rpArtist, string rpIconText)
|
|
{
|
|
/*
|
|
OCARINA2 Open-source music player and library manager
|
|
Copyright (C) 2023 Matyáš Caras
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
Code = code;
|
|
MenuFile = menuFile;
|
|
MenuOpen = menuOpen;
|
|
MenuExit = menuExit;
|
|
Music = music;
|
|
NoMusic = noMusic;
|
|
RPSong = rpSong;
|
|
RPArtist = rpArtist;
|
|
RPIconText = rpIconText;
|
|
}
|
|
|
|
public static Language Load(string code)
|
|
{
|
|
var assets = AvaloniaLocator.Current.GetService<IAssetLoader>();
|
|
using var stream = assets?.Open(new Uri($"avares://Ocarina2/Assets/Languages/{code}.json"));
|
|
if (stream == null) throw new Exception("Could not load language strings");
|
|
using var reader = new StreamReader(stream);
|
|
return JsonConvert.DeserializeObject<Language>(reader.ReadToEnd())!;
|
|
}
|
|
} |