From bc81aca9f4f026ba70ea88cc64ddce722a6dcc62 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 10 Apr 2022 14:33:35 +0700 Subject: [PATCH] Added Localizations to Weather app --- .../Weather.app/Localizations/English.lang | 18 +++++++++++ .../Weather.app/Localizations/Russian.lang | 18 +++++++++++ Applications/Weather.app/Main.lua | 32 ++++--------------- 3 files changed, 42 insertions(+), 26 deletions(-) create mode 100644 Applications/Weather.app/Localizations/English.lang create mode 100644 Applications/Weather.app/Localizations/Russian.lang diff --git a/Applications/Weather.app/Localizations/English.lang b/Applications/Weather.app/Localizations/English.lang new file mode 100644 index 00000000..d0cba6dc --- /dev/null +++ b/Applications/Weather.app/Localizations/English.lang @@ -0,0 +1,18 @@ +{ + winds = { + [0] = "N", + [1] = "NE", + [2] = "E", + [3] = "SE", + [4] = "S", + [5] = "SW", + [6] = "W", + [7] = "NW", + [8] = "N", + }, + mmHg = " mm Hg", + speed = " m/s, ", + population = "Population: ", + city = "Type city name here", + cityError = "Wrong result. Check city name and try again." +} \ No newline at end of file diff --git a/Applications/Weather.app/Localizations/Russian.lang b/Applications/Weather.app/Localizations/Russian.lang new file mode 100644 index 00000000..7baa1d8f --- /dev/null +++ b/Applications/Weather.app/Localizations/Russian.lang @@ -0,0 +1,18 @@ +{ + winds = { + [0] = "С", + [1] = "СВ", + [2] = "В", + [3] = "ЮВ", + [4] = "Ю", + [5] = "ЮЗ", + [6] = "З", + [7] = "СЗ", + [8] = "С", + }, + mmHg = " мм рт. ст.", + speed = " м/с, ", + population = "Популяция: ", + city = "Введите название города", + cityError = "Неправильный результат. Проверьте название города и повторите попытку." +} \ No newline at end of file diff --git a/Applications/Weather.app/Main.lua b/Applications/Weather.app/Main.lua index be7ff312..4e6addba 100755 --- a/Applications/Weather.app/Main.lua +++ b/Applications/Weather.app/Main.lua @@ -35,6 +35,7 @@ local config = { lastCityName = "Санкт-Петербург" } +local locale = system.getCurrentScriptLocalization() -------------------------------------------------------------------------------------------------------- local function newWeather(x, y, day) @@ -60,20 +61,10 @@ local function newWeather(x, y, day) end local temp = number.round(day.temp.min) .. " / " .. number.round(day.temp.max) .. " °C" - local pressure = number.round(day.pressure / 1.33322387415) .. " mm Hg" + local pressure = number.round(day.pressure / 1.33322387415) .. locale.mmHg local humidity = number.round(day.humidity) .. "%" - local winds = { - [0] = "N", - [1] = "NE", - [2] = "E", - [3] = "SE", - [4] = "S", - [5] = "SW", - [6] = "W", - [7] = "NW", - [8] = "N", - } - local wind = day.speed .. " m/s, " .. (winds[number.round(day.deg / 45)] or "N/A") + local winds = locale.winds + local wind = day.speed .. locale.speed .. (winds[number.round(day.deg / 45)] or "N/A") local function centerText(y, color, text) screen.drawText(math.floor(object.x + object.width / 2 - unicode.len(text) / 2), y, color, text) @@ -105,12 +96,12 @@ local function updateForecast() object.draw = function() bigLetters.drawText(object.x, object.y, 0xFFFFFF, number.round((currentDay.temp.max + currentDay.temp.min) / 2) .. "°") screen.drawText(object.x, object.y + 6, 0xFFFFFF, result.city.name .. ", " .. result.city.country) - screen.drawText(object.x, object.y + 7, 0xFFFFFF, "Population: " .. number.shorten(result.city.population, 2)) + screen.drawText(object.x, object.y + 7, 0xFFFFFF, locale.population .. number.shorten(result.city.population, 2)) end y = y + object.height + 1 - local input = weatherContainer:addChild(GUI.input(x + 2, y, 25, 1, 0xE1E1E1, 0x696969, 0x878787, 0xE1E1E1, 0x2D2D2D, "", "Type city name here")) + local input = weatherContainer:addChild(GUI.input(x + 2, y, 25, 1, 0xE1E1E1, 0x696969, 0x878787, 0xE1E1E1, 0x2D2D2D, "", locale.city)) input.onInputFinished = function() config.lastCityName = input.text updateForecast() @@ -152,14 +143,3 @@ if fs.exists(configPath) then end updateForecast() - - - - - - - - - - -