Ok Wim,
I think I have corrected for all eventualities, see if the new .rmskin in
the first post of this thread doesn't correct things for any of:
Language=en-US
Language=en-GB
Language=nl-NL
Language=fr-FR
Language=de-DE
Language=zh-CN
All the "calculating" will be done on the number converted to English format inches of mercury, and the "display" will be in the original number format and unit of measure.
I no longer depend on the textual unit of measure for anything... Hopefully we won't find that some country returns the actual value in something other than in / inHg or mb / hPa.
So for example, German will result in
1.012,2 hPa
Code: Select all
function Initialize()
measurePressure = SKIN:GetMeasure('MeasurePressure')
measureChange = SKIN:GetMeasure('MeasurePressureChange')
unitOfMeasure = SKIN:GetMeasure('MeasurePressureUnit')
end
function Update()
currentUnitOfMeasure = unitOfMeasure:GetStringValue()
currentPressure = measurePressure:GetStringValue()
currentChange = string.lower(measureChange:GetStringValue())
if currentPressure == '' then return currentPressure end
-- Removes the unicode "non-breaking space" used as separator in some languages
formattedPressure = currentPressure:gsub('[^%d\.,]', '')
-- Converts languages that use '.' as separator and ',' as decimal places to the opposite
if formattedPressure:match('%..*,') or formattedPressure:match('.*,[%d*]$')then
formattedPressure = formattedPressure:gsub('%.', 'dot')
formattedPressure = formattedPressure:gsub(',', '%.')
formattedPressure = formattedPressure:gsub('dot', '')
end
-- Removes commas from all values, so they can be treated as a number
formattedPressure = formattedPressure:gsub(',', '')
if tonumber(formattedPressure) >= 870 and tonumber(formattedPressure) <= 1084 then
convertedPressure = tostring(Round(tonumber(formattedPressure) * 0.0295300, 2))
else
convertedPressure = currentPressure
end
unitPosfix = ' '..currentUnitOfMeasure
SKIN:Bang('!SetOption', 'CurrentPressurePercent', 'Formula', tonumber(convertedPressure))
SKIN:Bang('!EnableMeasure', 'CurrentPressurePercent')
SKIN:Bang('!UpdateMeasure', 'CurrentPressurePercent')
if tonumber(convertedPressure) <= 28.59 then
if string.find(currentChange, 'falling') then
currentDescription = 'Increasingly Stormy'
elseif string.find(currentChange, 'steady') then
currentDescription = 'Remaining Stormy'
elseif string.find(currentChange, 'rising') then
currentDescription = 'Stormy, but Improving'
end
end
if tonumber(convertedPressure) >= 28.60 and tonumber(convertedPressure) <= 29.50 then
if string.find(currentChange, 'falling') then
currentDescription = 'Rain Forecasted'
elseif string.find(currentChange, 'steady') then
currentDescription = 'Remaining Rainy'
elseif string.find(currentChange, 'rising') then
currentDescription = 'Rainy, but Improving'
end
end
if tonumber(convertedPressure) >= 29.51 and tonumber(convertedPressure) <= 30.09 then
if string.find(currentChange, 'falling') then
currentDescription = 'Changing toward Rain'
elseif string.find(currentChange, 'steady') then
currentDescription = 'Change Possible'
elseif string.find(currentChange, 'rising') then
currentDescription = 'Changing toward Fair'
end
end
if tonumber(convertedPressure) >= 30.10 and tonumber(convertedPressure) <= 30.59 then
if string.find(currentChange, 'falling') then
currentDescription = 'Fair, but Degrading'
elseif string.find(currentChange, 'steady') then
currentDescription = 'Remaining Fair'
elseif string.find(currentChange, 'rising') then
currentDescription = 'Fair, and Improving'
end
end
if tonumber(convertedPressure) >= 30.60 then
if string.find(currentChange, 'falling') then
currentDescription = 'Very Dry, but Degrading'
elseif string.find(currentChange, 'steady') then
currentDescription = 'Remaining Very Dry'
elseif string.find(currentChange, 'rising') then
currentDescription = 'Increasingly Very Dry'
end
end
SKIN:Bang('!SetOption', 'MeterChange', 'InlinePattern2', '^$')
SKIN:Bang('!SetOption', 'MeterChange', 'InlinePattern3', '^$')
SKIN:Bang('!SetOption', 'MeterChange', 'InlinePattern4', '^$')
SKIN:Bang('!SetOption', 'MeterChange', 'InlinePattern5', '^$')
if string.find(currentChange, 'falling') and string.find(currentChange, 'rapidly') then
SKIN:Bang('!SetOption', 'MeterChange', 'InlinePattern2', '(◀ ◀)')
elseif string.find(currentChange, 'falling') and not string.find(currentChange, 'rapidly') then
SKIN:Bang('!SetOption', 'MeterChange', 'InlinePattern3', '◀ (◀)')
elseif string.find(currentChange, 'rising') and string.find(currentChange, 'rapidly') then
SKIN:Bang('!SetOption', 'MeterChange', 'InlinePattern4', '(▶ ▶)')
elseif string.find(currentChange, 'rising') and not string.find(currentChange, 'rapidly') then
SKIN:Bang('!SetOption', 'MeterChange', 'InlinePattern5', '(▶) ▶')
end
SKIN:Bang('!SetOption', 'MeterPressure', 'Text', currentPressure..unitPosfix)
SKIN:Bang('!SetOption', 'MeterDescription', 'Text', currentDescription)
return currentDescription
end
function Round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end