2017-07-05 17:21:52 +02:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET)
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using SafeExamBrowser.Core.Contracts;
|
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.Core.I18n
|
|
|
|
|
{
|
2017-07-06 10:56:03 +02:00
|
|
|
|
public class Text
|
2017-07-05 17:21:52 +02:00
|
|
|
|
{
|
2017-07-06 10:56:03 +02:00
|
|
|
|
private static Text instance;
|
|
|
|
|
private static readonly object @lock = new object();
|
2017-07-05 17:21:52 +02:00
|
|
|
|
|
2017-07-06 10:56:03 +02:00
|
|
|
|
private IDictionary<Key, string> cache = new Dictionary<Key, string>();
|
|
|
|
|
|
|
|
|
|
public Text(ITextResource resource)
|
2017-07-05 17:21:52 +02:00
|
|
|
|
{
|
|
|
|
|
if (resource == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(resource));
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-06 10:56:03 +02:00
|
|
|
|
cache = resource.LoadText();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Text Instance
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
lock (@lock)
|
|
|
|
|
{
|
|
|
|
|
return instance ?? new Text(new NullTextResource());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
lock (@lock)
|
|
|
|
|
{
|
|
|
|
|
instance = value ?? throw new ArgumentNullException(nameof(value));
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-05 17:21:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-06 10:56:03 +02:00
|
|
|
|
public string Get(Key key)
|
2017-07-05 17:21:52 +02:00
|
|
|
|
{
|
|
|
|
|
return cache.ContainsKey(key) ? cache[key] : $"Could not find string for key '{key}'!";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|