public HomeController(IJsonStringLocalizer <HomeController> localizer)
 {
     _localizer = localizer;
     _localizer.ClearMemCache(new List <CultureInfo>()
     {
         new CultureInfo("en-US")
     });
 }
示例#2
0
 public LinkController(
     ApplicationDbContext context,
     INotifier notifier,
     IJsonStringLocalizer localizer,
     ILogger <ArticleController> logger
     )
 {
     _context   = context;
     _notifier  = notifier;
     _localizer = localizer;
     _logger    = logger;
     _localizer.ClearMemCache(new List <CultureInfo>()
     {
         new CultureInfo("en-US")
     });
 }
示例#3
0
        private static void ExportAssetRegistry(IJsonStringLocalizer localizerFromFilesBot)
        {
            Console.WriteLine($"insert the path of export file 'export-{localizerFromFilesBot.Locale_AssetRegistryFileName}.json':");
            string path = Console.ReadLine();

            if (!Directory.Exists(path))
            {
                Console.WriteLine($"undefined path for 'export-{localizerFromFilesBot.Locale_AssetRegistryFileName}.json.");
                return;
            }
            string jsonExport = JsonConvert.SerializeObject(localizerFromFilesBot.locale_AssetRegistry, Formatting.Indented);
            var    exportFile = Path.Combine(path, $"export-{localizerFromFilesBot.Locale_AssetRegistryFileName}.json");

            using (StreamWriter sw = new StreamWriter(exportFile, false, Encoding.UTF8))
            {
                sw.Write(jsonExport);
            }
            Console.WriteLine($"datas are successfully expored({localizerFromFilesBot.locale_AssetRegistry.Count}) to:\n{exportFile}");
        }
示例#4
0
 public AccountController(
     UserManager <ApplicationUser> userManager,
     SignInManager <ApplicationUser> signInManager,
     IEmailSender emailSender,
     ILogger <AccountController> logger,
     IJsonStringLocalizer localizer,
     INotifier notifier)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _emailSender   = emailSender;
     _logger        = logger;
     _localizer     = localizer;
     _notifier      = notifier;
     _localizer.ClearMemCache(new List <CultureInfo>()
     {
         new CultureInfo("en-US")
     });
 }
示例#5
0
 public CommentController(
     ApplicationDbContext context,
     IAuthorizationService aus,
     UserManager <ApplicationUser> userManager,
     IFileIoHelper ioHelper,
     INotifier notifier,
     IConfiguration config,
     IJsonStringLocalizer localizer,
     ILogger <CommentController> logger
     )
 {
     _aus         = aus;
     _userManager = userManager;
     _context     = context;
     _ioHelper    = ioHelper;
     _notifier    = notifier;
     _config      = config;
     _localizer   = localizer;
     _logger      = logger;
 }
示例#6
0
 public UserController(
     ApplicationDbContext context,
     IAuthorizationService aus,
     UserManager <ApplicationUser> userManager,
     IFileIoHelper ioHelper,
     INotifier notifier,
     IConfiguration config,
     IJsonStringLocalizer localizer,
     ILogger <UserController> logger
     )
 {
     _aus         = aus;
     _userManager = userManager;
     _context     = context;
     _ioHelper    = ioHelper;
     _notifier    = notifier;
     _config      = config;
     _localizer   = localizer;
     _logger      = logger;
     _localizer.ClearMemCache(new List <CultureInfo>()
     {
         new CultureInfo("en-US")
     });
 }
 public ReloadController(IJsonStringLocalizer <ReloadController> localizer)
 {
     _localizer = localizer;
 }
示例#8
0
        static void Main(string[] args)
        {
            Global.Log.Initialize("FortniteAssetRegistryLoader", false);
            Global.Log.Information("test");
            var services = new ServiceCollection()
                           //.AddSingleton<IStringLocalizerFactory, JsonStringLocalizerFactory>()
                           .AddSingleton <IJsonStringLocalizer, JsonStringLocalizer>();
            //.AddLocalization(options => options.ResourcesPath = "Resources");
            var serviceProvider = services.BuildServiceProvider();

            IJsonStringLocalizer localizerFromFilesBot = serviceProvider.GetRequiredService <IJsonStringLocalizer>();

            /* var rr = CultureInfo.GetCultureInfo("en");
            *  var rr2 = CultureInfo.GetCultureInfo("pt");*/
            //string savePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "locale-AssetRegistry.json");
            if (!localizerFromFilesBot.AssetRegistryPath.Exists)
            {
                Console.WriteLine("**INVALID PATH** for saving 'locale-AssetRegistry.json' file.");
                Console.ReadLine();
                return;
            }
            else
            {
                Console.WriteLine("path for saving 'locale-AssetRegistry.json' file is **VALID**.");
            }
            Console.WriteLine("\nplease select your work:\n\n" +
                              //"1. LoadAssetRegistryBin file for new ids\n\n" +
                              "2. MergeAssetRegistry (merge with 'locale-AssetRegistry.json')\n" +
                              "3. ExportAssetRegistry Locales\n\n" +
                              "4. MergeBot (merge with 'locale-Bot.json')\n" +
                              "5. ExportBot Locales\n\n" +
                              "6. Export Translation Files\n" +
                              "\n0. EXIT");
            var result = int.TryParse(Console.ReadKey().KeyChar.ToString(), out int key);

            Console.WriteLine();
            if (result)
            {
                switch (key)
                {
                case 1:
                    //LoadAssetRegistryBin(localizerFromFilesBot);
                    break;

                case 2:
                    MergeAssetRegistry(localizerFromFilesBot);
                    break;


                case 3:
                    ExportAssetRegistry(localizerFromFilesBot);
                    break;

                case 4:
                    MergeBot(localizerFromFilesBot);
                    break;


                case 5:
                    ExportBot(localizerFromFilesBot);
                    break;

                case 6:
                    GenerateTranslation(localizerFromFilesBot);
                    break;

                default:
                    Console.WriteLine($"undefined term:{key}");
                    break;
                }
            }
            else
            {
                Console.WriteLine($"WRONG IMPUT");
            }
            Console.ReadLine();
        }
示例#9
0
        private static void MergeAssetRegistry(IJsonStringLocalizer localizerFromFilesBot)
        {
            Console.WriteLine($"insert the folder of new 'new-{localizerFromFilesBot.Locale_AssetRegistryFileName}.json' file:");
            string path = Console.ReadLine();

            string[] files = Directory.GetFiles(path, $"{localizerFromFilesBot.Locale_AssetRegistryFileName}*");
            if (path == "" || files.Length == 0)
            {
                Console.WriteLine($"undefined new-translated '{localizerFromFilesBot.Locale_AssetRegistryFileName}.json' file or location");
                return;
            }

            Console.WriteLine("please select a translated file index: ");
            Console.WriteLine();
            for (int i = 0; i < files.Length; i++)
            {
                var fl = new FileInfo(files[i]);
                Console.WriteLine($"[{i}]\t'{fl.Name}'");
            }
            Console.WriteLine();
            string indexNum = Console.ReadLine();

            Console.WriteLine();
            if (!int.TryParse(indexNum, out int findex))
            {
                Console.WriteLine($"undefined index was selected.");
                return;
            }
            else if (findex >= files.Length && findex < 0)
            {
                Console.WriteLine($"undefined index was selected.");
                return;
            }

            /*  else
             * {
             *    Console.WriteLine("file is selected.");
             * }*/
            var fif        = new FileInfo(files[findex]);
            var cultureKey = fif.Name.Split(".");
            List <JsonLocalization> newLocalizations = new List <JsonLocalization>();

            using (StreamReader sr = new StreamReader(fif.FullName))
            {
                var jsnl = JsonConvert.DeserializeObject <List <TranslateJsonLocalization> >(sr.ReadToEnd())
                           .Select(f => f.ToJsonLocalization(new CultureInfo(cultureKey[1]))).ToList();
                newLocalizations = jsnl;
                Console.WriteLine($"new file is loaded({newLocalizations.Count}).");
            }
            int countKey    = 0;
            int countLocale = 0;
            int oldCount    = localizerFromFilesBot.locale_AssetRegistry.Count;

            foreach (var item in newLocalizations)
            {
                foreach (var locale in item.Locales)
                {
                    if (locale.Value == "PUT_HERE")
                    {
                        continue;
                    }
                    localizerFromFilesBot.AddToAssetRegistry(item.Key, new CultureInfo(locale.Key), locale.Value);
                    string findDerivative = item.Key;
                    if (findDerivative == "EventCurrency_Scaling")
                    {
                        findDerivative = "EventScaling";
                    }
                    var derivatives = localizerFromFilesBot.locale_AssetRegistry
                                      .Where(f => f.Key.Substring(3).StartsWith($"_{findDerivative}", StringComparison.InvariantCultureIgnoreCase)).ToList();
                    foreach (var derivativeKey in derivatives)
                    {
                        localizerFromFilesBot.AddToAssetRegistry(derivativeKey.Key, new CultureInfo(locale.Key), locale.Value);
                    }
                    countLocale++;
                    countLocale += derivatives.Count;
                }
                countKey++;
            }
            Console.WriteLine($"{countKey} count keys(before:{oldCount}) and {countLocale} count locales are revised.");
            localizerFromFilesBot.SaveAssetRegistry();
        }
示例#10
0
        private static void GenerateTranslation(IJsonStringLocalizer localizerFromFilesBot)
        {
            Console.WriteLine("please specify a language code(i.e. 'en'or 'tr'):");
            string langCode = Console.ReadLine();

            Console.WriteLine();
            if (langCode.Length <= 3 && !int.TryParse(langCode, out int result))
            {
                CultureInfo cultureTo = new CultureInfo(langCode);
                List <TranslateJsonLocalization> AssetRegistryTranslations = new List <TranslateJsonLocalization>();
                foreach (var item in selectIdFromAssetRegistry)
                {
                    var select = localizerFromFilesBot.locale_AssetRegistry.FirstOrDefault(f => f.IsKeyEqual(item));
                    if (select != null)
                    {
                        if (!select.LocaleContains(cultureTo))
                        {
                            AssetRegistryTranslations.Add(select.ToTranslation(cultureTo));
                        }
                        else
                        {
                            Console.WriteLine();
                            Console.WriteLine($"value of '{item}' key is already translated.");
                            Console.WriteLine($"do you want to translate it again ? [y / n] (default: n)");
                            string answer = Console.ReadKey().Key.ToString().ToLowerInvariant();
                            if (answer == "y")
                            {
                                AssetRegistryTranslations.Add(select.ToTranslation(cultureTo));
                            }
                            else
                            {
                                Console.WriteLine();
                                Console.WriteLine($"value of '{item}' key is skipped.");
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine($"'{item}' key not found in 'locale_AssetRegistry'");
                    }
                }
                List <TranslateJsonLocalization> BotTranslations = new List <TranslateJsonLocalization>();
                foreach (var item in localizerFromFilesBot.locale_Bot)
                {
                    if (!item.LocaleContains(cultureTo))
                    {
                        BotTranslations.Add(item.ToTranslation(cultureTo));
                    }
                    else
                    {
                        Console.WriteLine();
                        Console.WriteLine($"value of '{item}' key is already translated.");
                        Console.WriteLine($"do you want to translate it again ? [y / n] (default: n)");
                        string answer = Console.ReadKey().Key.ToString().ToLowerInvariant();
                        if (answer == "y")
                        {
                            BotTranslations.Add(item.ToTranslation(cultureTo));
                        }
                        else
                        {
                            Console.WriteLine();
                            Console.WriteLine($"value of '{item}' key is skipped.");
                        }
                    }
                }
                string ExePath        = AppDomain.CurrentDomain.BaseDirectory;
                string translationDir = Path.Combine(ExePath, "newTranslations");
                if (!Directory.Exists(translationDir))
                {
                    Directory.CreateDirectory(translationDir);
                }
                var f1 = $"{localizerFromFilesBot.Locale_AssetRegistryFileName}.{cultureTo.TwoLetterISOLanguageName}.txt";
                using (StreamWriter sw = new StreamWriter(Path.Combine(translationDir, f1), false))
                {
                    string assets = JsonConvert.SerializeObject(AssetRegistryTranslations, Formatting.Indented);
                    sw.Write(assets);
                }

                var f2 = $"{localizerFromFilesBot.Locale_BotFileName}.{cultureTo.TwoLetterISOLanguageName}.txt";
                using (StreamWriter sw = new StreamWriter(Path.Combine(translationDir, f2), false))
                {
                    string bots = JsonConvert.SerializeObject(BotTranslations, Formatting.Indented);
                    sw.Write(bots);
                }
                Console.WriteLine();
                Console.WriteLine($"{f1}\nand\n{f2}\n are successfully exported to '{translationDir}'");
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("wrong format for 'GenerateTranslation'");
                return;
            }
        }
示例#11
0
 public PriorityManager(IDiscordRestApi discordRestApi, IFTNPowerRepository fTNPowerRepository, IJsonStringLocalizer translation)
 {
     DiscordRestApi = discordRestApi;
     Translation    = translation;
     Repo           = fTNPowerRepository;
 }