It is currently September 16th, 2019, 11:30 pm

lua question

Discuss the use of Lua in Script measures.
User avatar
dvo
Posts: 541
Joined: February 7th, 2016, 6:08 am

Re: lua question

dvo » May 15th, 2016, 1:35 pm

now i gonna make it a normal clock running next to it with same skin :)
done ;)
User avatar
jsmorley
Developer
Posts: 19456
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: lua question

jsmorley » May 15th, 2016, 4:21 pm

This should keep you busy for basically the rest of your life dvo... ;-)

https://forum.rainmeter.net/viewtopic.php?p=123416#p123416
User avatar
dvo
Posts: 541
Joined: February 7th, 2016, 6:08 am

Re: lua question

dvo » May 15th, 2016, 9:47 pm

why couse you added some more :) i already have seen that kind of scripts what's new :)
but what you guest is that i could not alter some parts in your lua
if you made is ajustible i could make him all lua ...
i guess scripts are made only for programmers i can only alter scripts not re-write it.
it's a shame but it's still true .. but i translated 3/4 from your lua already.
just missing day, month, and the weather couse all is english at base.
so if your willing to make those replacable like the one you already replaced,
i could make it whole :) :rofl:
User avatar
dvo
Posts: 541
Joined: February 7th, 2016, 6:08 am

Re: lua question

dvo » May 16th, 2016, 9:45 am

This should keep you busy for basically the rest of your life dvo... ;-)
ow shit now is my life over jsmorley........... :D

Dutch version :
This is your 'TextClock2.ini'

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Metadata]
Name=TextClock2.1
Author=JSMorley /dvo 
Version=2.1 dutch - May 16, 2016
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0
Information=Displays the time with a "minutes before/after hour" text format||i.e "QUARTER AFTER TEN"||Displays the date in text format||Displays the weather in text format||Requires Rainmeter 4.0 or later.

[Variables]
; LocationCode can be obtained at http://wxdata.weather.com/wxdata/search/search?where=YourCityName
LocationCode=NLXX0019
; UnitOfMeasure can be "f" (Fahrenheit / Imperial) or "m" (Celsius / Metric)
UnitOfMeasure=m

AfterText=over
UntilText=voor
HalfText=

[WeatherParent]
Measure=Plugin
Plugin=WebParser
URL=https://wxdata.weather.com/wxdata/weather/local/#LocationCode#?cc=*&unit=#UnitOfMeasure#&dayf=1
RegExp=(?siU)<ut>(.*)</ut>.*<cc>.*<tmp>(.*)</tmp>.*<t>(.*)</t>
FinishAction=[!EnableMeasure MeasureScript]

[UnitsChild]
Measure=Plugin
Plugin=WebParser
URL=[WeatherParent]
StringIndex=1

[TemperatureChild]
Measure=Plugin
Plugin=WebParser
URL=[WeatherParent]
StringIndex=2

[ConditionsChild]
Measure=Plugin
Plugin=WebParser
URL=[WeatherParent]
StringIndex=3
FormatLocale=Local
Substitute="Fair":"mooi","Cloudy":"bewolkt","Showers in the Vicinity":"regen","Partly":"gedeeltelijk","Mostly":"dicht","Fog":"mist","Clouds":"Wolken","Light":"licht","Rain":"regen","Sunny":"zonnig","Clear":"helder","and":"met","Windy":"wind","Drizzle":"ijzel","Freezing":"koude"


[MeasureScript]
Measure=Script
ScriptFile=TextClock2.lua
Disabled=1

[MeasureTimer]
Measure=Time
TimeStampLocale=nl-NL
FormatLocale=Local
Format=Het is vandaag %A %d %B 
substitute="01":" een","02":" twee","03":" drie","04":" vier","05":" vijf","06":" zes","07":" zeven","08":" acht","09":" negen","10":" tien","11":" elf","12":" twaalf","13":" dertien","14":" veertien","15":" vijftien","16":" zestien","17":" zeventien","18":" achtien","19":" negentien","20":" twintig","21":" een en twintig","22":" twee en twintig","23":" drie en twintig","24":"vier en twintig","25":" vijf en twintig","26":" zes en twintig","27":" zeven en twintig","28":" acht en twintig","29":" negen en twintig","30":" dertig","31":" een en dertig"
DynamicVariables=1


[MeterTime]
Meter=String
InlineSetting=Face | Segoe UI
InlineSetting2=Size | 20
InlineSetting3=Weight | 100
InlineSetting4=Color | 255,255,255,255
InlineSetting5=Case | Upper
InlineSetting6=Size | 17
InlinePattern6=(?i)minute || minutes
InlineSetting7=Size | 17
InlinePattern7=(?i)#AfterText# || #UntilText# || #HalfText#
InlineSetting8=Size | 17
InlinePattern8=(?i)it's
InlineSetting9=Size | 17
InlinePattern9=(?i)in the
SolidColor=0,0,0,1
AntiAlias=1


[MeterTimer]
Meter=string
MeasureName=MeasureTimer
Y=0R
AntiAlias=1
InlinePattern7=#MeterDay# 

[MeterConditions]
Meter=String
Y=0R
InlineSetting=Face | Segoe UI
InlineSetting2=Size | 20
InlineSetting3=Weight | 100
InlineSetting4=Color | 255,255,255,255
InlineSetting5=Case | Upper
InlineSetting6=Size | 17
InlinePattern6=(?i)the weather is
InlineSetting7=Size | 17
InlinePattern7=(?i)and
SolidColor=0,0,0,1
AntiAlias=1

[MeterTemperature]
Meter=String
Y=0R
InlineSetting=Face | Segoe UI
InlineSetting2=Size | 20
InlineSetting3=Weight | 100
InlineSetting4=Color | 255,255,255,255
InlineSetting5=Case | Upper
InlineSetting6=Size | 17
InlinePattern6=(?i)it's
InlineSetting7=Size | 17
InlinePattern7=(?i)at
InlineSetting8=Size | 17
InlinePattern8=(?i)degrees
InlineSetting9=Size | 17
InlinePattern9=(?i)and
SolidColor=0,0,0,1
AntiAlias=1

and here your TextClock2.lua

Code: Select all

function Initialize()

		measureUnits = SKIN:GetMeasure('UnitsChild')
		measureTemperature = SKIN:GetMeasure('TemperatureChild')
		measureConditions = SKIN:GetMeasure('ConditionsChild')
		
		afterText = SKIN:GetVariable('AfterText')
		untilText = SKIN:GetVariable('UntilText')
		halfText = SKIN:GetVariable('HalfText')
		
		weekdayTable = {}
		
		weekdayTable['Monday'] = 'MAANDAG'
		weekdayTable['Tuesday'] = 'DINSDAG'
		weekdayTable['Wednesday'] = 'WOENSDAG'
		weekdayTable['Thursday'] = 'DONDERDAG'
		weekdayTable['Friday'] = 'VRIJDAG'
		weekdayTable['Saturday'] = 'ZATERDAG'
		weekdayTable['Sunday'] = 'ZONDAG'
		
		

		dayTable = {}
		
		dayTable['0'] = ''
		dayTable['1'] = 'eerste'
		dayTable['2'] = 'tweede'
		dayTable['3'] = 'derde'
		dayTable['4'] = 'vierde'
		dayTable['5'] = 'vijfde'
		dayTable['6'] = 'zesde'
		dayTable['7'] = 'zevende'
		dayTable['8'] = 'achtste'
		dayTable['9'] = 'negende'
		dayTable['10'] = 'tiende'
		dayTable['11'] = 'elfde'
		dayTable['12'] = 'twaalfste'
		dayTable['13'] = 'dertiende'
		dayTable['14'] = 'veertiende'
		dayTable['15'] = 'vijftienste'
		dayTable['16'] = 'zestiende'
		dayTable['17'] = 'zeventiende'
		dayTable['18'] = 'achttiende'
		dayTable['19'] = 'negentiende'
		dayTable['20'] = 'twintigste'
		dayTable['30'] = 'dertigste'
		
		numTable = {}
		
		numTable['0'] = 'nul'
		numTable['1'] = 'een'
		numTable['2'] = 'twee'
		numTable['3'] = 'drie'
		numTable['4'] = 'vier'
		numTable['5'] = 'vijf'
		numTable['6'] = 'zes'
		numTable['7'] = 'zeven'
		numTable['8'] = 'acht'
		numTable['9'] = 'negen'
		numTable['10'] = 'tien'
		numTable['11'] = 'elf'
		numTable['12'] = 'twaalf'
		numTable['13'] = 'dertien'
		numTable['14'] = 'veertien'
		numTable['15'] = 'vijftien'
		numTable['16'] = 'zestien'
		numTable['17'] = 'zeventien'
		numTable['18'] = 'achttien'
		numTable['19'] = 'negentien'
		numTable['20'] = 'twintig'
		numTable['30'] = 'dertig'
		numTable['40'] = 'veertig'
		numTable['50'] = 'vijftig'
		numTable['60'] = 'zestig'
		numTable['70'] = 'zeventig'
		numTable['80'] = 'tachtig'
		numTable['90'] = 'negentig'
		numTable['100'] = 'honderd'

end

function Update()

	TimeString()
	DateString()
	ConditionsString()
	TemperatureString()
	
end

function TimeString()

	hour24 = tonumber(os.date('%H'))
	hour12 = tonumber(os.date('%I'))
	minute = tonumber(os.date('%M'))

	if hour24 < 12 then
		partOfDay = 'morgen'
	elseif hour24 >= 12 and hour24 < 17 then
		partOfDay = 'middag'
	else
		partOfDay = 'avond'
	end
	
	if minute < 30 then
		adjustedMinute = minute
		midText = afterText
	elseif minute == 30 then
		adjustedMinute = minute
		midText = halfText
	else
		midText = untilText
		adjustedMinute = 60 - minute
		hour12 = hour12 == 12 and 1 or hour12 + 1
	end

	if adjustedMinute >= 20 and adjustedMinute < 30 then 
		if adjustedMinute == 20 then
			minuteText = 'twintig minuten'
		else
			minuteText = numTable[tostring(adjustedMinute - 20)].. ' en twintig minuten'
		end
	else
		if adjustedMinute < 10 then
			if adjustedMinute == 1 then
				minuteText = numTable[tostring(adjustedMinute)]..' minuut'
			else
				minuteText = numTable[tostring(adjustedMinute)]..' minuten'
			end
		elseif adjustedMinute == 15 then
			minuteText = 'kwart'
		elseif adjustedMinute == 30 then
			minuteText = 'half'
		else
			minuteText = numTable[tostring(adjustedMinute)]
		end
	end

	if hour24 == 12 and minute == 0 then
		SKIN:Bang('!SetOption', 'MeterTime', 'Text', 'Het is '..numTable[tostring(hour12)]..' uur in de middag')
	end
	if hour24 == 0 and minute == 0 then
		SKIN:Bang('!SetOption', 'MeterTime', 'Text', 'Het is '..numTable[tostring(hour12)]..' uur in de avond')
	end	
	if adjustedMinute == 0 then
		SKIN:Bang('!SetOption', 'MeterTime', 'Text', 'Het is '..numTable[tostring(hour12)]..' uur'..' in de '..partOfDay)
	else
		SKIN:Bang('!SetOption', 'MeterTime', 'Text', 'het is '..minuteText.. ' '..midText..' '..numTable[tostring(hour12)]..' in de '..partOfDay)
	end

end

function DateString()

	weekdayName = os.date('%A')
	
	monthName = os.date('%B')
	
	dayNumber = os.date('%d')

	if tonumber(dayNumber) < 20 or tonumber(dayNumber) % 10 == 0 then
		dayText = dayTable[dayNumber]
	else
		dayLeft = string.sub(dayNumber, 1, 1) * 10
		dayRight = string.sub(dayNumber, 2)
		dayText = numTable[tostring(dayLeft)]..'-'..dayTable[dayRight]

	end
	
	SKIN:Bang('!SetOption', 'MeterDate', 'Text', weekdayName..', de '..dayText..' van '..monthName)
	
end

function ConditionsString()

	conditionsText = measureConditions:GetStringValue()
	conditionsText = string.gsub(conditionsText, ' / ', ' and ')
	SKIN:Bang('!SetOption', 'MeterConditions', 'Text', 'het weer is '..conditionsText)

end

function TemperatureString()

	tempUnit = measureUnits:GetStringValue()
	tempValue = tonumber(measureTemperature:GetStringValue())
	
	if tempUnit == 'C' then
		if tempValue > 31.7 then tempDesc = 'extreem heet'
			elseif tempValue > 26.1 then tempDesc = 'warm'
			elseif tempValue > 15 then tempDesc = 'redelijk warm'
			elseif tempValue > 9.4 then tempDesc = 'redelijk koud'
			elseif tempValue > 0 then tempDesc = 'erg koud'
			else tempDesc = 'extreem koud'
		end
	end
	
	if tempUnit == 'F' then
		if tempValue > 89 then tempDesc = 'extreem heet'
			elseif tempValue > 79 then tempDesc = 'warm'
			elseif tempValue > 59 then tempDesc = 'redelijk warm'
			elseif tempValue > 49 then tempDesc = 'redelijk koud'
			elseif tempValue > 32 then tempDesc = 'erg koud'
			else tempDesc = 'extreem koud'
		end
	end	
	
	if tempValue < 0 then
		tempValue = math.abs(tempValue)
		belowZero = 1
	else
		belowZero = 0
	end
	
	if tempValue >= 100 then
		hundredText = 'honderd en '
		tempValue = tempValue - 100
	else
		hundredText = ''
	end
	
	if tempValue < 20 or tempValue % 10 == 0 then
		tempText = numTable[tostring(tempValue)]
	else
		tempLeft = string.sub(tempValue, 1, 1) * 10
		tempRight = string.sub(tempValue, 2)
		tempText = numTable[tostring(tempLeft)]..'-'..numTable[tempRight]
	end
	
	if belowZero == 0 then
		SKIN:Bang('!SetOption', 'MeterTemperature', 'Text', 'het is '..tempDesc..' met '..hundredText..tempText..' graden')
	else
		SKIN:Bang('!SetOption', 'MeterTemperature', 'Text', 'het is '..tempDesc..' met '..hundredText..tempText..' graden onder nul')
	end
	
end
User avatar
jsmorley
Developer
Posts: 19456
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: lua question

jsmorley » May 16th, 2016, 11:52 am

dvo,

Try changing the URL in the skin .ini to:

URL=https://wxdata.weather.com/wxdata/weather/local/#LocationCode#?cc=*&unit=#UnitOfMeasure#&dayf=1&locale=nl_NL

That should cause the wxdata feed to return the "conditions text" in Dutch.

I'm not convinced this could easily be made language-neutral by just setting up tables to replace all the elements with strings that can easily be translated. While this is true of the basic elements, like the numbers, and the names of days of the week and names of months, and the weather "conditions" can be returned in many different languages by wxdata.weather.com, the way things are "spoken" (in a sense) are pretty aggressively English in nature in this, and in fact pretty aggressively American-English. While it might be possible (you certainly have made a good start) to modify the Lua to change the structure of how things are presented in your language, as well as translate the stuff that makes sense in tables, I'm not sure it could easily be made generic.

A simple example is the fact that at 2:30 I would say "Half past two" and you would say "Half three". That is not a translation, but an "exception", and I suspect there are many of them in the course of this for different countries, regions, languages, cultures, and even generations of age. Hell, in the UK, a guy in another town 20 miles away can sound like a "damn foreigner" to you.
User avatar
dvo
Posts: 541
Joined: February 7th, 2016, 6:08 am

Re: lua question

dvo » May 16th, 2016, 2:27 pm

http://flyinghyrax.deviantart.com/art/Elementary-2-0-426588102

this skin just has a translator built in to it ? :D :o
and even you in the credits :rolmfao:
Last edited by dvo on May 16th, 2016, 2:30 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 19456
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: lua question

jsmorley » May 16th, 2016, 2:30 pm

"It is impossible for an Englishman to open his mouth without making some other Englishman despise him,"
-- George Bernard Shaw
User avatar
jsmorley
Developer
Posts: 19456
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: lua question

jsmorley » May 16th, 2016, 2:35 pm

dvo wrote:http://flyinghyrax.deviantart.com/art/Elementary-2-0-426588102

this skin just has a translator built in to it ? :D :o
and even you in the credits :rolmfao:
Sure, but that is just brute-force translation. That suite of skins doesn't really have to be too concerned about how things are expressed in a colloquial fashion by different cultures.

Anyway, my Lua is open for anyone to modify as they see fit. While it is programming, you will find that Lua is pretty easy compared to other programming languages.
User avatar
dvo
Posts: 541
Joined: February 7th, 2016, 6:08 am

Re: lua question

dvo » May 16th, 2016, 2:36 pm

My therapist told me the way to achieve true inner peace is to finish what I start. So far I’ve finished two bags of M&Ms and a chocolate cake. I feel better already. :D
dave barry :) the english man :rolmfao:
User avatar
jsmorley
Developer
Posts: 19456
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: lua question

jsmorley » May 16th, 2016, 2:48 pm

Even the simple numbers are not as straightforward as all that when you are spelling them out and not using numerals...

English: fifty-six
Spanish: cincuenta y seis
French: cinquante six
Italian: cinquantasei
German: sechsundfünfzig
Dutch: zesenvijftig

If I go to Google Translate and put this:

it's seven minutes to eleven in the morning
on monday, the sixteenth of may
the weather is sunny
it's fairly cool at fifty-five degrees

and translate it to Dutch, I get:

het zeven voor elf in de ochtend
Op maandag , de zestiende mei
het is zonnig
het is vrij koel ' vijfenvijftig graden

While the only Dutch I know is "Vertrouw nooit een Duitser", I'm betting that is not even close to how you would express the same thing.