From fdb6b409e15e5b8ecf82dabeff872939245e60ec Mon Sep 17 00:00:00 2001 From: Adrian Hill Date: Mon, 16 Sep 2024 09:54:28 +0200 Subject: [PATCH] Format code with JuliaFormatter (#47) * Run JuliaFormatter * Add formatting tests * Fix language selection in example notebook --- .JuliaFormatter.toml | 1 + .gitignore | 1 + demo_module.jl | 12 +- example.jl | 170 +++++++++------ src/aside.jl | 101 +++++---- src/computational_thinking.jl | 384 +++++++++++++++++++++------------- src/footnotes.jl | 316 +++++++++++++--------------- src/i18n/chinese.jl | 156 ++++++++++---- src/i18n/english.jl | 168 +++++++++++---- src/i18n/german.jl | 230 +++++++++++++++----- src/i18n/i18n.jl | 325 +++++++++++++++++----------- src/i18n/russian.jl | 174 +++++++++++---- src/i18n/spanish.jl | 192 +++++++++++++---- src/latex.jl | 10 +- src/other.jl | 90 ++++---- src/present.jl | 33 +-- src/robustlocalresource.jl | 35 ++-- test/Project.toml | 4 + test/runtests.jl | 83 ++++---- 19 files changed, 1589 insertions(+), 896 deletions(-) create mode 100644 .JuliaFormatter.toml create mode 100644 test/Project.toml diff --git a/.JuliaFormatter.toml b/.JuliaFormatter.toml new file mode 100644 index 0000000..323237b --- /dev/null +++ b/.JuliaFormatter.toml @@ -0,0 +1 @@ +style = "blue" diff --git a/.gitignore b/.gitignore index c9137a7..aae257f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /Manifest.toml +/test/Manifest.toml data diff --git a/demo_module.jl b/demo_module.jl index 13f5e50..af6e899 100644 --- a/demo_module.jl +++ b/demo_module.jl @@ -1,11 +1,11 @@ module Demo - export hello, hundred - - function hello() - return "Hello!" - end - hundred = 100 +export hello, hundred +function hello() + return "Hello!" end +hundred = 100 + +end # module diff --git a/example.jl b/example.jl index 753fae3..3c67124 100644 --- a/example.jl +++ b/example.jl @@ -1,5 +1,5 @@ ### A Pluto.jl notebook ### -# v0.19.27 +# v0.19.42 using Markdown using InteractiveUtils @@ -7,7 +7,14 @@ using InteractiveUtils # This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error). macro bind(def, element) quote - local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end + local iv = try + Base.loaded_modules[Base.PkgId( + Base.UUID("6e696c72-6542-2067-7265-42206c756150"), + "AbstractPlutoDingetjes", + )].Bonds.initial_value + catch + b -> missing + end local el = $(esc(element)) global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el) el @@ -22,18 +29,17 @@ md"# [PlutoTeachingTools.jl](https://github.com/JuliaPluto/PlutoTeachingTools.jl # ╔═╡ 84ccb960-41f8-430d-bd73-a7c0248cfb95 md""" -Language for common prompts: $(@bind lang Select(["en"=>"English","de"=>"German","es"=>"Spanish", -"ru"=>"Russian", "zh"=>"chinese"]]) ) +Language for common prompts: $(@bind lang Select(["en"=>"English","de"=>"German","es"=>"Spanish","ru"=>"Russian", "zh"=>"chinese"])) """ # ╔═╡ 657c3eea-1ef6-11ed-3e82-5daad2bc19a1 begin - using PlutoTeachingTools - # Optionally override default language choice (lang defined in widget above) - set_language!( PlutoTeachingTools.get_language(lang) ) + using PlutoTeachingTools + # Optionally override default language choice (lang defined in widget above) + set_language!(PlutoTeachingTools.get_language(lang)) - nb_link_prefix = PlutoRunner.notebook_id[] |>string # for making urls to notebook - pkg_cell_link = "#" * (PlutoRunner.currently_running_cell_id[] |> string) # for making urls to this cell + nb_link_prefix = string(PlutoRunner.notebook_id[]) # for making urls to notebook + pkg_cell_link = "#" * (string(PlutoRunner.currently_running_cell_id[])) # for making urls to this cell end; # ╔═╡ f0704e56-7e97-4c92-bbdd-76d7a873e6d8 @@ -45,7 +51,9 @@ md""" """ # ╔═╡ 8c3f1fe2-c934-4743-b30b-07dc97aeac46 -almost(md"You're right that the answer is a positive number, but the value isn't quite right.") +almost( + md"You're right that the answer is a positive number, but the value isn't quite right." +) # ╔═╡ b48468f0-eeaa-4e1a-ad0b-3cfe42b6ab15 correct() @@ -78,13 +86,16 @@ warning_box(md"Be extra careful here.") blockquote("A insightful quote that spans two lines.") # ╔═╡ e9c10995-ff3d-4a47-82d1-051b0b7cc65d -blockquote("Logic will get you from A to B. Imagination will take you everywhere.", md"-- A. Einstein") +blockquote( + "Logic will get you from A to B. Imagination will take you everywhere.", + md"-- A. Einstein", +) # ╔═╡ 4758e75c-1729-4dab-964c-7a2ee9798534 TODO("Remember to add good documentation.") # ╔═╡ 39766d40-81a8-498b-83d9-c6f27c131db7 -TODO("Remember to add good documentation.", heading="TODO #2") +TODO("Remember to add good documentation."; heading="TODO #2") # ╔═╡ 462025ab-b520-499d-9925-4b5770b80355 md""" @@ -111,25 +122,25 @@ md""" """ # ╔═╡ 438c621a-1991-476f-9889-55c053941e1b -a= 1 +a = 1 # ╔═╡ 1381ca68-cc1d-4fe7-9587-ee13a5db92ab type_eq(a, Float64) # ╔═╡ b52ff55b-3a8a-44e6-9bf6-2b6f9dda5e33 -type_isa(a,Real) +type_isa(a, Real) # ╔═╡ 0cb5c037-8c2f-4fca-a999-63f9a4f9b891 -wrong_type(:a,Float64) +wrong_type(:a, Float64) # ╔═╡ 4a380230-f977-4ff7-9114-9d4075bba240 eval(Meta.parse(PlutoTeachingTools.code_for_check_type_funcs)) # ╔═╡ 42cb6d16-98e0-4ea8-8b54-370df71fe54e -display_msg_if_fail(check_type_isa(:a,a,Float64)) +display_msg_if_fail(check_type_isa(:a, a, Float64)) # ╔═╡ 1f3e04b4-28f9-4bb8-a233-fd061ac2ee75 -display_msg_if_fail(check_type_isa(:a,a,Int64)) # should display nothing +display_msg_if_fail(check_type_isa(:a, a, Int64)) # should display nothing # ╔═╡ db745245-805a-478b-b3f5-c7974fab0e9c md""" @@ -140,23 +151,29 @@ md""" response_1 = missing # replace with your answer # ╔═╡ 8f980fa3-559e-491d-8a84-34a4678fa53d -if ismissing(response_1) still_missing() end +if ismissing(response_1) + still_missing() +end # ╔═╡ 5f95518f-62cd-4869-b6cf-85a7860f38ec response_2 = "Insert your response here." # ╔═╡ 3e12dbd9-f02a-479d-9eff-234ac88e059b -PlutoTeachingTools.keep_working_if_var_contains_substr(:response_2,response_2,"Insert your") +PlutoTeachingTools.keep_working_if_var_contains_substr( + :response_2, response_2, "Insert your" +) # ╔═╡ c8811462-874c-47da-bb34-797234046fdf -PlutoTeachingTools.keep_working_if_var_contains_substr(:response_2,response_2,"should display nothing") +PlutoTeachingTools.keep_working_if_var_contains_substr( + :response_2, response_2, "should display nothing" +) # ╔═╡ 40155961-e8bb-41d1-bf54-178cf2a0c524 responce_1 = missing # ╔═╡ 957ec770-ab5b-4b0b-a38d-46834d96fa68 if !ismissing(responce_1) && responce_1 == 42 - PlutoTeachingTools.confetti() + PlutoTeachingTools.confetti() end # ╔═╡ 7596325b-7a1b-4fad-bac3-ae6743e3f8dd @@ -164,15 +181,15 @@ md"""# Robust Local Resources""" # ╔═╡ 2bfcfe6d-221e-4619-b794-92e44494460b begin - url = "https://raw.githubusercontent.com/gist/fonsp/9a36c183e2cad7c8fc30290ec95eb104/raw/ca3a38a61f95cd58d79d00b663a3c114d21e284e/cute.svg" - path = "data/cute.svg" + url = "https://raw.githubusercontent.com/gist/fonsp/9a36c183e2cad7c8fc30290ec95eb104/raw/ca3a38a61f95cd58d79d00b663a3c114d21e284e/cute.svg" + path = "data/cute.svg" end; # ╔═╡ 43a47026-4b09-4c20-9ccb-a766a17f8ff4 -RobustLocalResource(url, path, cache=false) # specify to not save a local copy +RobustLocalResource(url, path; cache=false) # specify to not save a local copy # ╔═╡ 4774a4d7-d5f1-40e4-8c2f-f0f96e9242ce -RobustLocalResource(url, path, :width=>200, :alt=>"Pluto logo") # add html attributes +RobustLocalResource(url, path, :width => 200, :alt => "Pluto logo") # add html attributes # ╔═╡ d61ec51d-60c4-4f48-8179-2c8045416953 md""" @@ -185,29 +202,32 @@ md""" """ # ╔═╡ c46d1e7c-df6e-460e-a103-a486d27932c9 -Foldable("Want more?",md"Extra info") +Foldable("Want more?", md"Extra info") # ╔═╡ fb77557c-cbf1-4d91-bf4b-76abd54a4024 answer_box( -md""" -The stone has a greater force becasue force is given by Newtons 2nd law: + md""" + The stone has a greater force becasue force is given by Newtons 2nd law: -```math -F=m \times a -``` + ```math + F=m \times a + ``` -It has a greater mass, therefore $m$ is larger. This then results in a larger force $F$ -""" + It has a greater mass, therefore $m$ is larger. This then results in a larger force $F$ + """ ) # ╔═╡ 8eb551ef-a9c0-43e3-aea7-d83679436e93 -answer_box(md"""Three""", invite="1+2 = ?") +answer_box(md"""Three"""; invite="1+2 = ?") # ╔═╡ fb4ff876-a668-40ab-8d30-bfaa858849e4 protip(md"The `CSV.read` function has lots of useful optional arguments.") # ╔═╡ 69a9e9f3-a72e-4935-a200-2842010f1e54 -protip(md"Several of these functions have optional arguments.", invite="Invitation to learn more") +protip( + md"Several of these functions have optional arguments."; + invite="Invitation to learn more", +) # ╔═╡ 08794ef8-4e10-4913-808e-06ac194625b6 md""" @@ -217,10 +237,10 @@ The vertical offset can be set by the optional parameter `v_offset`. """ # ╔═╡ 77bb3822-2a1d-4e23-b852-6b6202069efa -aside(tip(md"Extra information to consider.") ) +aside(tip(md"Extra information to consider.")) # ╔═╡ cc66ef97-36f2-478c-961b-dd8ab2bda4ac -aside(tip(md"Even more information to consider."),v_offset=100) +aside(tip(md"Even more information to consider."); v_offset=100) # ╔═╡ 0b2a4490-7e29-42c0-af9a-e99b5540d154 set_aside_width(400) @@ -231,7 +251,7 @@ md""" """ # ╔═╡ f49ccb75-7cb8-49ce-95b9-ed59033a589d -A = rand(2,2) +A = rand(2, 2) # ╔═╡ af5673b5-a7f9-4033-ac9b-845254f62c98 md"Now, you can include variables like $A=$ $(latexify_md(A)) inside markdown." @@ -266,7 +286,9 @@ TwoColumnWideLeft(md"Left col", md"Right col") TwoColumnWideRight(md"Left col", md"Right col") # ╔═╡ 44d651d3-ce42-4061-b193-da7c31efed8e -TwoColumnWideLeft(warning_box(md"Discussion of figure on right."), RobustLocalResource(url, path)) +TwoColumnWideLeft( + warning_box(md"Discussion of figure on right."), RobustLocalResource(url, path) +) # ╔═╡ 7859ad2b-7e87-442c-8684-f731f2512a42 md""" @@ -347,23 +369,29 @@ FootnotesNumbered() # ╔═╡ f4201010-71d1-4889-99e7-abb774612a4d begin - mls_link = "#" * (PlutoRunner.currently_running_cell_id[] |> string) - md"# Multi-language support" + mls_link = "#" * (string(PlutoRunner.currently_running_cell_id[])) + md"# Multi-language support" end # ╔═╡ d6b3f009-22e4-4b21-8986-a29e3f261c3b Markdown.parse("""See also [multi-language support]($mls_link) section below""") # ╔═╡ ef32d891-0a7a-4803-95ae-a930787c243a -preferred_text( (en=md"Hello",de=md"Hallo",es=md"Hola") ) +preferred_text((en=md"Hello", de=md"Hallo", es=md"Hola")) # ╔═╡ d3762092-e31d-4b96-840a-3939b89f60b7 -tip(preferred_text( (en=md"Remember to add good documentation.", - de=md"Denken Sie daran, eine gute Dokumentation hinzuzufügen.", - es=md"Recuerde agregar buena documentación") )) +tip( + preferred_text(( + en=md"Remember to add good documentation.", + de=md"Denken Sie daran, eine gute Dokumentation hinzuzufügen.", + es=md"Recuerde agregar buena documentación", + )), +) # ╔═╡ 93e4e977-efb1-48c7-ac4c-c578140135ee -Markdown.parse("""See also [package cell]($pkg_cell_link) for overriding default language selected from `ENV[LANG]`.""") +Markdown.parse( + """See also [package cell]($pkg_cell_link) for overriding default language selected from `ENV[LANG]`.""", +) # ╔═╡ 743491af-3d4b-4dee-9ad7-2372ba4e97bd md""" @@ -373,9 +401,9 @@ md""" # ╔═╡ 23afc83f-e971-4356-a30e-1b7a247ff38d begin - MyModule = @ingredients "demo_module.jl" # provided by PlutoLinks.jl - import .MyModule: Demo - import .Demo: hello + MyModule = @ingredients "demo_module.jl" # provided by PlutoLinks.jl + import .MyModule: Demo + import .Demo: hello end # ╔═╡ d4b1b5f2-b4ae-4988-aded-79398949f1c8 @@ -402,7 +430,7 @@ PlutoUI = "~0.7.52" PLUTO_MANIFEST_TOML_CONTENTS = """ # This file is machine-generated - editing it directly is not advised -julia_version = "1.9.2" +julia_version = "1.10.5" manifest_format = "2.0" project_hash = "2af2aaef1ea67811bc114f2d0bf7f61179b912c7" @@ -437,7 +465,7 @@ version = "0.11.4" [[deps.CompilerSupportLibraries_jll]] deps = ["Artifacts", "Libdl"] uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" -version = "1.0.5+0" +version = "1.1.1+0" [[deps.Dates]] deps = ["Printf"] @@ -523,21 +551,26 @@ version = "0.16.1" [[deps.LibCURL]] deps = ["LibCURL_jll", "MozillaCACerts_jll"] uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" -version = "0.6.3" +version = "0.6.4" [[deps.LibCURL_jll]] deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" -version = "7.84.0+0" +version = "8.4.0+0" [[deps.LibGit2]] -deps = ["Base64", "NetworkOptions", "Printf", "SHA"] +deps = ["Base64", "LibGit2_jll", "NetworkOptions", "Printf", "SHA"] uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" +[[deps.LibGit2_jll]] +deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll"] +uuid = "e37daf67-58a4-590a-8e99-b0245dd2ffc5" +version = "1.6.4+0" + [[deps.LibSSH2_jll]] deps = ["Artifacts", "Libdl", "MbedTLS_jll"] uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" -version = "1.10.2+0" +version = "1.11.0+1" [[deps.Libdl]] uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" @@ -573,14 +606,14 @@ uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" [[deps.MbedTLS_jll]] deps = ["Artifacts", "Libdl"] uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" -version = "2.28.2+0" +version = "2.28.2+1" [[deps.Mmap]] uuid = "a63ad114-7e13-5084-954f-fe012c677804" [[deps.MozillaCACerts_jll]] uuid = "14a3606d-f60d-562e-9121-12d972cd8159" -version = "2022.10.11" +version = "2023.1.10" [[deps.NetworkOptions]] uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" @@ -589,7 +622,7 @@ version = "1.2.0" [[deps.OpenBLAS_jll]] deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"] uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" -version = "0.3.21+4" +version = "0.3.23+4" [[deps.OrderedCollections]] git-tree-sha1 = "2e73fe17cac3c62ad1aebe70d44c963c3cfdc3e3" @@ -605,7 +638,7 @@ version = "2.7.2" [[deps.Pkg]] deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"] uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" -version = "1.9.2" +version = "1.10.0" [[deps.PlutoHooks]] deps = ["InteractiveUtils", "Markdown", "UUIDs"] @@ -652,7 +685,7 @@ deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" [[deps.Random]] -deps = ["SHA", "Serialization"] +deps = ["SHA"] uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" [[deps.Reexport]] @@ -685,16 +718,17 @@ uuid = "6462fe0b-24de-5631-8697-dd941f90decc" [[deps.SparseArrays]] deps = ["Libdl", "LinearAlgebra", "Random", "Serialization", "SuiteSparse_jll"] uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" +version = "1.10.0" [[deps.Statistics]] deps = ["LinearAlgebra", "SparseArrays"] uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" -version = "1.9.0" +version = "1.10.0" [[deps.SuiteSparse_jll]] -deps = ["Artifacts", "Libdl", "Pkg", "libblastrampoline_jll"] +deps = ["Artifacts", "Libdl", "libblastrampoline_jll"] uuid = "bea87d4a-7f5b-5778-9afe-8cc45184846c" -version = "5.10.1+6" +version = "7.2.1+1" [[deps.TOML]] deps = ["Dates"] @@ -730,28 +764,28 @@ uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" [[deps.Zlib_jll]] deps = ["Libdl"] uuid = "83775a58-1f1d-513f-b197-d71354ab007a" -version = "1.2.13+0" +version = "1.2.13+1" [[deps.libblastrampoline_jll]] deps = ["Artifacts", "Libdl"] uuid = "8e850b90-86db-534c-a0d3-1478176c7d93" -version = "5.8.0+0" +version = "5.11.0+0" [[deps.nghttp2_jll]] deps = ["Artifacts", "Libdl"] uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" -version = "1.48.0+0" +version = "1.52.0+1" [[deps.p7zip_jll]] deps = ["Artifacts", "Libdl"] uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" -version = "17.4.0+0" +version = "17.4.0+2" """ # ╔═╡ Cell order: # ╟─cd581a51-fb2b-4579-9a7d-0d723ad5d467 # ╠═dee4aa68-e5eb-4a8a-869f-867e61de5ec5 -# ╟─84ccb960-41f8-430d-bd73-a7c0248cfb95 +# ╠═84ccb960-41f8-430d-bd73-a7c0248cfb95 # ╟─d6b3f009-22e4-4b21-8986-a29e3f261c3b # ╠═657c3eea-1ef6-11ed-3e82-5daad2bc19a1 # ╠═f0704e56-7e97-4c92-bbdd-76d7a873e6d8 diff --git a/src/aside.jl b/src/aside.jl index b2ad0db..7db2c25 100644 --- a/src/aside.jl +++ b/src/aside.jl @@ -4,71 +4,68 @@ export aside, set_aside_width aside_has_been_setup = false get_aside_has_been_setup()::Bool = aside_has_been_setup -set_aside_has_been_setup(b::Bool = true) = aside_has_been_setup = b +set_aside_has_been_setup(b::Bool=true) = aside_has_been_setup = b aside_width = 300 get_aside_width()::Int64 = aside_width """ Changes width of all aside's """ -function set_aside_width(width::Integer) - aside_width = width - set_aside_has_been_setup(true) - @htl(""" - - """) +function set_aside_width(width::Integer) + aside_width = width + set_aside_has_been_setup(true) + @htl(""" + + """) end - """ Displays text on right hand side of Pluto notebook. Optional `v_offset` allows shifting down (positive) or up (negative). Optional integer parameter `width` defaults to 300px. Often combined with `tip(md"text")`. """ -function aside(x; v_offset::Integer = 0 ) - width = get_aside_width() - if get_aside_has_been_setup() - @htl(""" - - """) - else - set_aside_has_been_setup(true) - @htl(""" - - - """) +function aside(x; v_offset::Integer=0) + width = get_aside_width() + if get_aside_has_been_setup() + @htl(""" + + """) + else + set_aside_has_been_setup(true) + @htl(""" + + + """) end end - - diff --git a/src/computational_thinking.jl b/src/computational_thinking.jl index 704a248..dba96e1 100644 --- a/src/computational_thinking.jl +++ b/src/computational_thinking.jl @@ -2,7 +2,7 @@ using Random # , Distributions # not sure if we need that using Markdown using LaTeXStrings -using HypertextLiteral +using HypertextLiteral export hint, tip, protip, almost, warning_box, question_box, answer_box, danger, keyconcept export correct, still_missing, still_nothing, wrong_type @@ -16,81 +16,171 @@ export blockquote export display_msg_if_fail "Hint box with arguement as text." -hint(text, lang::AbstractLanguage = default_language[]) = Markdown.MD(Markdown.Admonition("hint", hint_str(lang), [text])); +function hint(text, lang::AbstractLanguage=default_language[]) + return Markdown.MD(Markdown.Admonition("hint", hint_str(lang), [text])) +end "Tip box with arguement as text." -tip(text, lang::AbstractLanguage = default_language[]) = Markdown.MD(Markdown.Admonition("tip", tip_str(lang), [text])); +function tip(text, lang::AbstractLanguage=default_language[]) + return Markdown.MD(Markdown.Admonition("tip", tip_str(lang), [text])) +end "Tip box with arguement as text." -protip(text; lang::AbstractLanguage = default_language[], invite = protip_invite_str(lang), boxlabel = protip_boxlabel_str(lang)) = Foldable(invite, Markdown.MD(Markdown.Admonition("tip", boxlabel, [text])) ); -protip(text, invite, lang::AbstractLanguage = default_language[]; boxlabel = protip_boxlabel_str(lang)) = protip(text; lang, invite, boxlabel); +function protip( + text; + lang::AbstractLanguage=default_language[], + invite=protip_invite_str(lang), + boxlabel=protip_boxlabel_str(lang), +) + return Foldable(invite, Markdown.MD(Markdown.Admonition("tip", boxlabel, [text]))) +end +function protip( + text, + invite, + lang::AbstractLanguage=default_language[]; + boxlabel=protip_boxlabel_str(lang), +) + return protip(text; lang, invite, boxlabel) +end "Answer box with arguement as text." -answer_box(text; lang::AbstractLanguage = default_language[], invite = answer_invite_str(lang), boxlabel = answer_boxlabel_str(lang)) = Foldable(invite, Markdown.MD(Markdown.Admonition("answer", boxlabel, [text])) ); -answer_box(text, invite, lang::AbstractLanguage = default_language[]; boxlabel = answer_boxlabel_str(lang)) = answer(text; lang, invite, boxlabel); +function answer_box( + text; + lang::AbstractLanguage=default_language[], + invite=answer_invite_str(lang), + boxlabel=answer_boxlabel_str(lang), +) + return Foldable(invite, Markdown.MD(Markdown.Admonition("answer", boxlabel, [text]))) +end +function answer_box( + text, + invite, + lang::AbstractLanguage=default_language[]; + boxlabel=answer_boxlabel_str(lang), +) + return answer(text; lang, invite, boxlabel) +end "Admonition box labeled a warning with arguement as text." -almost(text, lang::AbstractLanguage = default_language[]) = Markdown.MD(Markdown.Admonition("warning", almost_str(lang), [text])); +function almost(text, lang::AbstractLanguage=default_language[]) + return Markdown.MD(Markdown.Admonition("warning", almost_str(lang), [text])) +end "Warning box with arguement as text." -warning_box(text, lang::AbstractLanguage = default_language[]) = Markdown.MD(Markdown.Admonition("warning", warning_box_str(lang), [text])); +function warning_box(text, lang::AbstractLanguage=default_language[]) + return Markdown.MD(Markdown.Admonition("warning", warning_box_str(lang), [text])) +end "Question box with arguement as text." -question_box(text, lang::AbstractLanguage = default_language[]) = Markdown.MD(Markdown.Admonition("question", question_box_str(lang), [text])); +function question_box(text, lang::AbstractLanguage=default_language[]) + return Markdown.MD(Markdown.Admonition("question", question_box_str(lang), [text])) +end "Key concept box with concept name and description as input arguments." -keyconcept(concept, text, lang::AbstractLanguage = default_language[]) = Markdown.MD(Markdown.Admonition("key-concept", keyconcept_str(lang), [md"**$concept**", text])) +function keyconcept(concept, text, lang::AbstractLanguage=default_language[]) + return Markdown.MD( + Markdown.Admonition("key-concept", keyconcept_str(lang), [md"**$concept**", text]) + ) +end "Danger box with arguement as text." -danger(text, lang::AbstractLanguage = default_language[]) = Markdown.MD(Markdown.Admonition("danger", danger_str(lang), [text])); +function danger(text, lang::AbstractLanguage=default_language[]) + return Markdown.MD(Markdown.Admonition("danger", danger_str(lang), [text])) +end "Admonition box with reminder to replace missing." -still_missing(;lang::AbstractLanguage = default_language[], text=still_missing_text_str(lang)) = Markdown.MD(Markdown.Admonition("warning", still_missing_str(lang), [text])); -still_missing(text, lang::AbstractLanguage = default_language[]) = still_missing(;lang, text); +function still_missing(; + lang::AbstractLanguage=default_language[], text=still_missing_text_str(lang) +) + return Markdown.MD(Markdown.Admonition("warning", still_missing_str(lang), [text])) +end +still_missing(text, lang::AbstractLanguage=default_language[]) = still_missing(; lang, text) "Admonition box with reminder to replace nothing." -still_nothing(; lang::AbstractLanguage = default_language[], text=still_nothing_text_str(lang)) = Markdown.MD(Markdown.Admonition("warning", still_nothing_str(lang), [text])); -still_nothing(text, lang::AbstractLanguage = default_language[]) = still_nothing(;lang, text); +function still_nothing(; + lang::AbstractLanguage=default_language[], text=still_nothing_text_str(lang) +) + return Markdown.MD(Markdown.Admonition("warning", still_nothing_str(lang), [text])) +end +still_nothing(text, lang::AbstractLanguage=default_language[]) = still_nothing(; lang, text) -wrong_type(lang::AbstractLanguage = default_language[]) = Markdown.MD(Markdown.Admonition("danger", wrong_type_str(lang), [wrong_type_text_str(lang)])) +function wrong_type(lang::AbstractLanguage=default_language[]) + return Markdown.MD( + Markdown.Admonition("danger", wrong_type_str(lang), [wrong_type_text_str(lang)]) + ) +end -wrong_type(var::Symbol, type::Type, lang::AbstractLanguage = default_language[]; text=wrong_type_text_str(lang, var, type)) = Markdown.MD(Markdown.Admonition("danger", wrong_type_str(lang), [text])) +function wrong_type( + var::Symbol, + type::Type, + lang::AbstractLanguage=default_language[]; + text=wrong_type_text_str(lang, var, type), +) + return Markdown.MD(Markdown.Admonition("danger", wrong_type_str(lang), [text])) +end "Admonition box with reminder that function name passed is not defined." -func_not_defined(func_name, lang::AbstractLanguage = default_language[]) = Markdown.MD(Markdown.Admonition("danger", func_not_defined_str(lang), [func_not_defined_text_str(func_name, lang)])); +function func_not_defined(func_name, lang::AbstractLanguage=default_language[]) + return Markdown.MD( + Markdown.Admonition( + "danger", + func_not_defined_str(lang), + [func_not_defined_text_str(func_name, lang)], + ), + ) +end "Admonition box with reminder that variable name passed is not defined." -var_not_defined(variable_name, lang::AbstractLanguage = default_language[]) = Markdown.MD(Markdown.Admonition("danger", var_not_defined_str(lang), [var_not_defined_text_str(variable_name, lang)])); +function var_not_defined(variable_name, lang::AbstractLanguage=default_language[]) + return Markdown.MD( + Markdown.Admonition( + "danger", + var_not_defined_str(lang), + [var_not_defined_text_str(variable_name, lang)], + ), + ) +end "Admonition box with reminder that variable name passed is not defined. (deprecated)" -not_defined(variable_name, lang::AbstractLanguage = default_language[]) = var_not_defined(variable_name, lang) +function not_defined(variable_name, lang::AbstractLanguage=default_language[]) + return var_not_defined(variable_name, lang) +end "Admonition box warning that the answer isn't quite right." -keep_working(; lang::AbstractLanguage = default_language[], text=keep_working_text_str(lang)) = Markdown.MD(Markdown.Admonition("danger", keep_working_str(lang), [text])); -keep_working(text, lang::AbstractLanguage = default_language[]) = keep_working(;lang, text); - -function keep_working_if_var_contains_substr(var::Symbol,str::Union{String,Markdown.MD},substr::String, lang::AbstractLanguage = default_language[]) -# I had to remove !@isdefined(var) due to how Pluto puts variables into different modules -# not exported, so provide function with same name in notebook - if ismissing(var) - still_missing() - elseif isnothing(var) - still_nothing() - else - if typeof(str) == Markdown.MD - str = Markdown.plain(str) - end - if occursin(substr,str) - keep_working(keep_working_update_str(var, lang)) - end - end +function keep_working(; + lang::AbstractLanguage=default_language[], text=keep_working_text_str(lang) +) + return Markdown.MD(Markdown.Admonition("danger", keep_working_str(lang), [text])) +end +keep_working(text, lang::AbstractLanguage=default_language[]) = keep_working(; lang, text); + +function keep_working_if_var_contains_substr( + var::Symbol, + str::Union{String,Markdown.MD}, + substr::String, + lang::AbstractLanguage=default_language[], +) + # I had to remove !@isdefined(var) due to how Pluto puts variables into different modules + # not exported, so provide function with same name in notebook + if ismissing(var) + still_missing() + elseif isnothing(var) + still_nothing() + else + if typeof(str) == Markdown.MD + str = Markdown.plain(str) + end + if occursin(substr, str) + keep_working(keep_working_update_str(var, lang)) + end + end end type_isa(var, t::Union{Type,Vector{Type},Vector{DataType}}) = (any(typeof(var) .<: t)) type_eq(var, t::Union{Type,Vector{Type},Vector{DataType}}) = (any(typeof(var) .== t)) # To use functions in notebook, run eval(Meta.parse(code_for_check_type_funcs)) -code_for_check_type_funcs = """ +const code_for_check_type_funcs = """ begin function check_type_isa(sym::Symbol, var, t::Union{Type,Vector{Type},Vector{DataType}}, lang::AbstractLanguage = PlutoTeachingTools.default_language[]) if ismissing(var) @@ -150,8 +240,10 @@ end """ "Box with random positive message." -correct(;lang::AbstractLanguage = default_language[], text=rand(yays(lang))) = Markdown.MD(Markdown.Admonition("correct", correct_str(lang), [text])); -correct(text, lang::AbstractLanguage = default_language[]) = correct(;lang, text); +function correct(; lang::AbstractLanguage=default_language[], text=rand(yays(lang))) + return Markdown.MD(Markdown.Admonition("correct", correct_str(lang), [text])) +end +correct(text, lang::AbstractLanguage=default_language[]) = correct(; lang, text) #TODO_str = html"TODO" #TODO() = TODO_str @@ -162,116 +254,116 @@ Useful for demarcating work-in-progress sections or parts that could be imporved """ function TODO end -TODO(text, lang::AbstractLanguage = default_language[]; heading=todo_str(lang)) = TODO(; lang, text, heading) - -function TODO(;lang::AbstractLanguage = default_language[], text = "", heading=todo_str(lang)) -@htl(""" -
-
-
-

⚠ $heading ⚠

-

$text

-
-
-
- - - -""") +function TODO(text, lang::AbstractLanguage=default_language[]; heading=todo_str(lang)) + return TODO(; lang, text, heading) end -# Useful strings for embedding in markdown -nbsp = html" " - -function display_msg_if_fail(x; msg_pass = nothing) - if !x.passed - x.msg - else - msg_pass - end +function TODO(; lang::AbstractLanguage=default_language[], text="", heading=todo_str(lang)) + @htl(""" +
+
+
+

⚠ $heading ⚠

+

$text

+
+
+
+ + + + """) end - +# Useful strings for embedding in markdown +const nbsp = html" " + +function display_msg_if_fail(x; msg_pass=nothing) + if !x.passed + x.msg + else + msg_pass + end +end """ Displays a nice blockquote. Useful for including quotes by well known figures or useful nuggets of wisdom. """ -function blockquote(text,author="") -@htl(""" -
-

-$text -

-

-$author -
-
- -""") +function blockquote(text, author="") + @htl(""" +
+

+ $text +

+

+ $author +
+
+ + """) end diff --git a/src/footnotes.jl b/src/footnotes.jl index 460961b..18d8f4e 100644 --- a/src/footnotes.jl +++ b/src/footnotes.jl @@ -9,180 +9,166 @@ using HypertextLiteral using PlutoUI function FootnotesInlineNumbered() -html""" - - - -""" + html""" + + + + """ end - - function FootnotesBottomNumbered() -html""" - -""" + html""" + + """ end - - function FootnotesNumbered() - PlutoUI.combine() do Child - @htl(""" - $(Child(FootnotesInlineNumbered())) - $(Child(FootnotesBottomNumbered())) - """) - end + PlutoUI.combine() do Child + @htl(""" + $(Child(FootnotesInlineNumbered())) + $(Child(FootnotesBottomNumbered())) + """) + end end +function FootnotesInlineStyleSuperscript() + return html""" + + """ +end +function FootnotesInlineStyleSubscript() + return html""" + + """ +end -FootnotesInlineStyleSuperscript()=html""" - -""" - - - -FootnotesInlineStyleSubscript()=html""" - -""" - - - -FootnotesInlineStyleBaseline()=html""" - -""" - - +function FootnotesInlineStyleBaseline() + return html""" + + """ +end -export FootnotesInlineNumbered -export FootnotesBottomNumbered +export FootnotesInlineNumbered +export FootnotesBottomNumbered export FootnotesNumbered -export FootnotesInlineStyleSuperscript -export FootnotesInlineStyleSubscript -export FootnotesInlineStyleBaseline - - +export FootnotesInlineStyleSuperscript +export FootnotesInlineStyleSubscript +export FootnotesInlineStyleBaseline diff --git a/src/i18n/chinese.jl b/src/i18n/chinese.jl index 8453e87..fbdd13e 100644 --- a/src/i18n/chinese.jl +++ b/src/i18n/chinese.jl @@ -4,57 +4,123 @@ using Markdown using ..PlutoTeachingTools -abstract type Chinese <: AbstractLanguage end +abstract type Chinese <: AbstractLanguage end struct ChineseZH <: Chinese end # computational_thinking.jl -PlutoTeachingTools.hint_str(lang::Lang) where {Lang <: Chinese} = "提示" -PlutoTeachingTools.tip_str(lang::Lang) where {Lang <: Chinese} = "提醒" -PlutoTeachingTools.protip_invite_str(lang::Lang) where {Lang <: Chinese} = "想了解更多?" -PlutoTeachingTools.protip_boxlabel_str(lang::Lang) where {Lang <: Chinese} = "提醒" -PlutoTeachingTools.answer_invite_str(lang::Lang) where {Lang <: Chinese} = "想要看答案?" -PlutoTeachingTools.answer_boxlabel_str(lang::Lang) where {Lang <: Chinese} = "答案" -PlutoTeachingTools.almost_str(lang::Lang) where {Lang <: Chinese} = "差不多了!" -PlutoTeachingTools.warning_box_str(lang::Lang) where {Lang <: Chinese} = "警告:" -PlutoTeachingTools.question_box_str(lang::Lang) where {Lang <: Chinese} = "问题:" -PlutoTeachingTools.danger_str(lang::Lang) where {Lang <: Chinese} = "危险:" -PlutoTeachingTools.keyconcept_str(lang::Lang) where {Lang <: Chinese} = "🎯 核心概念" -PlutoTeachingTools.still_missing_str(lang::Lang) where {Lang <: Chinese} = "缺少回应" -PlutoTeachingTools.still_missing_text_str(lang::Lang) where {Lang <: Chinese} = md"把`missing`替换为你的答案." -PlutoTeachingTools.still_nothing_str(lang::Lang) where {Lang <: Chinese} = "让我们开始吧!" -PlutoTeachingTools.still_nothing_text_str(lang::Lang) where {Lang <: Chinese} = md"把 `nothing` 替换为你的答案." -PlutoTeachingTools.wrong_type_str(lang::Lang) where {Lang <: Chinese} = "类型错误" -PlutoTeachingTools.wrong_type_text_str(lang::Lang) where {Lang <: Chinese} = md"检查你的响应的类型." -PlutoTeachingTools.wrong_type_text_str(lang::Lang, var, type) where {Lang <: Chinese} = md"$var 的类型应该是 $type" -PlutoTeachingTools.func_not_defined_str(lang::Lang) where {Lang <: Chinese} = "糟糕!" -PlutoTeachingTools.func_not_defined_text_str(func_name, lang::Lang) where {Lang <: Chinese} = md"请确定你定义了一个名为 **$(Markdown.Code(string(func_name)))** 的函数。" -PlutoTeachingTools.var_not_defined_str(lang::Lang) where {Lang <: Chinese} = "糟糕!" -PlutoTeachingTools.var_not_defined_text_str(variable_name, lang::Lang) where {Lang <: Chinese} = md"请确定你定义了一个名为 **$(Markdown.Code(string(variable_name)))** 的变量。" -PlutoTeachingTools.keep_working_str(lang::Lang) where {Lang <: Chinese} = "继续加油!" -PlutoTeachingTools.keep_working_text_str(lang::Lang) where {Lang <: Chinese} = md"答案还不太对." -PlutoTeachingTools.keep_working_update_str(var, lang::Lang) where {Lang <: Chinese} = md"确保更新单元格设置 $var." -PlutoTeachingTools.yays(lang::Lang) where {Lang <: Chinese} = [md"很棒!", md"耶 ❤", md"很棒! 🎉", md"干得好", md"继续保持!", md"干得不错!", md"帅呆了", md"你做对了!", md"继续往下看吧."] -PlutoTeachingTools.correct_str(lang::Lang) where {Lang <: Chinese} = "懂了!" -PlutoTeachingTools.todo_str(lang::Lang) where {Lang <: Chinese} = "待办" - -PlutoTeachingTools.check_type_isa_missing_text_str(sym, lang::Lang) where {Lang <: Chinese} = md"变量 $sym 仍然被设置为 missing." -PlutoTeachingTools.check_type_isa_wrong_type_text_str(sym, lang::Lang) where {Lang <: Chinese} = "$sym 的类型不对. 它应该是 <: " -PlutoTeachingTools.check_type_isa_wrong_type_one_of_text_str(lang::Lang) where {Lang <: Chinese} = "一个" -PlutoTeachingTools.check_type_isa_wrong_type_or_text_str(lang::Lang) where {Lang <: Chinese} = "或者" -PlutoTeachingTools.check_type_isa_not_missing_text_str(sym, lang::Lang) where {Lang <: Chinese} = md"$sym 类型正确." -PlutoTeachingTools.check_type_isa_type_error_str(sym, lang::Lang) where {Lang <: Chinese} = "类型错误" - -PlutoTeachingTools.check_type_eq_missing_text_str(sym, lang::Lang) where {Lang <: Chinese} = md"变量 $sym 仍被置为 missing." -PlutoTeachingTools.check_type_eq_wrong_type_single_text_str(sym, type, lang::Lang) where {Lang <: Chinese} = "$sym 的类型应该是 $type." -PlutoTeachingTools.check_type_eq_wrong_type_multi_text_str(sym, lang::Lang) where {Lang <: Chinese} = "$sym 应该是一个 " -PlutoTeachingTools.check_type_eq_type_error_str(lang::Lang) where {Lang <: Chinese} = "类型错误" -PlutoTeachingTools.check_type_eq_correct_str(sym, lang::Lang) where {Lang <: Chinese} = md"$sym 类型正确." +PlutoTeachingTools.hint_str(lang::Lang) where {Lang<:Chinese} = "提示" +PlutoTeachingTools.tip_str(lang::Lang) where {Lang<:Chinese} = "提醒" +PlutoTeachingTools.protip_invite_str(lang::Lang) where {Lang<:Chinese} = "想了解更多?" +PlutoTeachingTools.protip_boxlabel_str(lang::Lang) where {Lang<:Chinese} = "提醒" +PlutoTeachingTools.answer_invite_str(lang::Lang) where {Lang<:Chinese} = "想要看答案?" +PlutoTeachingTools.answer_boxlabel_str(lang::Lang) where {Lang<:Chinese} = "答案" +PlutoTeachingTools.almost_str(lang::Lang) where {Lang<:Chinese} = "差不多了!" +PlutoTeachingTools.warning_box_str(lang::Lang) where {Lang<:Chinese} = "警告:" +PlutoTeachingTools.question_box_str(lang::Lang) where {Lang<:Chinese} = "问题:" +PlutoTeachingTools.danger_str(lang::Lang) where {Lang<:Chinese} = "危险:" +PlutoTeachingTools.keyconcept_str(lang::Lang) where {Lang<:Chinese} = "🎯 核心概念" +PlutoTeachingTools.still_missing_str(lang::Lang) where {Lang<:Chinese} = "缺少回应" +function PlutoTeachingTools.still_missing_text_str(lang::Lang) where {Lang<:Chinese} + md"把`missing`替换为你的答案." +end +PlutoTeachingTools.still_nothing_str(lang::Lang) where {Lang<:Chinese} = "让我们开始吧!" +function PlutoTeachingTools.still_nothing_text_str(lang::Lang) where {Lang<:Chinese} + md"把 `nothing` 替换为你的答案." +end +PlutoTeachingTools.wrong_type_str(lang::Lang) where {Lang<:Chinese} = "类型错误" +PlutoTeachingTools.wrong_type_text_str(lang::Lang) where {Lang<:Chinese} = md"检查你的响应的类型." +function PlutoTeachingTools.wrong_type_text_str(lang::Lang, var, type) where {Lang<:Chinese} + md"$var 的类型应该是 $type" +end +PlutoTeachingTools.func_not_defined_str(lang::Lang) where {Lang<:Chinese} = "糟糕!" +function PlutoTeachingTools.func_not_defined_text_str( + func_name, lang::Lang +) where {Lang<:Chinese} + md"请确定你定义了一个名为 **$(Markdown.Code(string(func_name)))** 的函数。" +end +PlutoTeachingTools.var_not_defined_str(lang::Lang) where {Lang<:Chinese} = "糟糕!" +function PlutoTeachingTools.var_not_defined_text_str( + variable_name, lang::Lang +) where {Lang<:Chinese} + md"请确定你定义了一个名为 **$(Markdown.Code(string(variable_name)))** 的变量。" +end +PlutoTeachingTools.keep_working_str(lang::Lang) where {Lang<:Chinese} = "继续加油!" +PlutoTeachingTools.keep_working_text_str(lang::Lang) where {Lang<:Chinese} = md"答案还不太对." +function PlutoTeachingTools.keep_working_update_str(var, lang::Lang) where {Lang<:Chinese} + md"确保更新单元格设置 $var." +end +function PlutoTeachingTools.yays(lang::Lang) where {Lang<:Chinese} + return [ + md"很棒!", + md"耶 ❤", + md"很棒! 🎉", + md"干得好", + md"继续保持!", + md"干得不错!", + md"帅呆了", + md"你做对了!", + md"继续往下看吧.", + ] +end +PlutoTeachingTools.correct_str(lang::Lang) where {Lang<:Chinese} = "懂了!" +PlutoTeachingTools.todo_str(lang::Lang) where {Lang<:Chinese} = "待办" + +function PlutoTeachingTools.check_type_isa_missing_text_str( + sym, lang::Lang +) where {Lang<:Chinese} + md"变量 $sym 仍然被设置为 missing." +end +function PlutoTeachingTools.check_type_isa_wrong_type_text_str( + sym, lang::Lang +) where {Lang<:Chinese} + return "$sym 的类型不对. 它应该是 <: " +end +function PlutoTeachingTools.check_type_isa_wrong_type_one_of_text_str( + lang::Lang +) where {Lang<:Chinese} + return "一个" +end +function PlutoTeachingTools.check_type_isa_wrong_type_or_text_str( + lang::Lang +) where {Lang<:Chinese} + return "或者" +end +function PlutoTeachingTools.check_type_isa_not_missing_text_str( + sym, lang::Lang +) where {Lang<:Chinese} + md"$sym 类型正确." +end +function PlutoTeachingTools.check_type_isa_type_error_str( + sym, lang::Lang +) where {Lang<:Chinese} + return "类型错误" +end + +function PlutoTeachingTools.check_type_eq_missing_text_str( + sym, lang::Lang +) where {Lang<:Chinese} + md"变量 $sym 仍被置为 missing." +end +function PlutoTeachingTools.check_type_eq_wrong_type_single_text_str( + sym, type, lang::Lang +) where {Lang<:Chinese} + return "$sym 的类型应该是 $type." +end +function PlutoTeachingTools.check_type_eq_wrong_type_multi_text_str( + sym, lang::Lang +) where {Lang<:Chinese} + return "$sym 应该是一个 " +end +PlutoTeachingTools.check_type_eq_type_error_str(lang::Lang) where {Lang<:Chinese} = "类型错误" +function PlutoTeachingTools.check_type_eq_correct_str(sym, lang::Lang) where {Lang<:Chinese} + md"$sym 类型正确." +end # other.jl -PlutoTeachingTools.full_width_mode_str(lang::Lang) where {Lang <: Chinese} = "全屏模式" +PlutoTeachingTools.full_width_mode_str(lang::Lang) where {Lang<:Chinese} = "全屏模式" # present.jl -PlutoTeachingTools.present_str(lang::Lang) where {Lang <: Chinese} = "演示" -PlutoTeachingTools.present_mode_str(lang::Lang) where {Lang <: Chinese} = "演示模式" +PlutoTeachingTools.present_str(lang::Lang) where {Lang<:Chinese} = "演示" +PlutoTeachingTools.present_mode_str(lang::Lang) where {Lang<:Chinese} = "演示模式" end diff --git a/src/i18n/english.jl b/src/i18n/english.jl index 93f91e0..ca2eda0 100644 --- a/src/i18n/english.jl +++ b/src/i18n/english.jl @@ -4,57 +4,135 @@ using Markdown using ..PlutoTeachingTools -abstract type English <: AbstractLanguage end +abstract type English <: AbstractLanguage end struct EnglishUS <: English end # computational_thinking.jl -PlutoTeachingTools.hint_str(lang::Lang) where {Lang <: English} = "Hint" -PlutoTeachingTools.tip_str(lang::Lang) where {Lang <: English} = "Tip" -PlutoTeachingTools.protip_invite_str(lang::Lang) where {Lang <: English} = "Curious to learn more?" -PlutoTeachingTools.protip_boxlabel_str(lang::Lang) where {Lang <: English} = "Pro Tip" -PlutoTeachingTools.answer_invite_str(lang::Lang) where {Lang <: English} = "Want to see the answer?" -PlutoTeachingTools.answer_boxlabel_str(lang::Lang) where {Lang <: English} = "Answer" -PlutoTeachingTools.almost_str(lang::Lang) where {Lang <: English} = "Almost there!" -PlutoTeachingTools.warning_box_str(lang::Lang) where {Lang <: English} = "Warning:" -PlutoTeachingTools.question_box_str(lang::Lang) where {Lang <: English} = "Question:" -PlutoTeachingTools.danger_str(lang::Lang) where {Lang <: English} = "Beware!" -PlutoTeachingTools.keyconcept_str(lang::Lang) where {Lang <: English} = "🎯 Key concept" -PlutoTeachingTools.still_missing_str(lang::Lang) where {Lang <: English} = "Missing Response" -PlutoTeachingTools.still_missing_text_str(lang::Lang) where {Lang <: English} = md"Replace `missing` with your answer." -PlutoTeachingTools.still_nothing_str(lang::Lang) where {Lang <: English} = "Here we go!" -PlutoTeachingTools.still_nothing_text_str(lang::Lang) where {Lang <: English} = md"Replace `nothing` with your answer." -PlutoTeachingTools.wrong_type_str(lang::Lang) where {Lang <: English} = "Type Error" -PlutoTeachingTools.wrong_type_text_str(lang::Lang) where {Lang <: English} = md"Check the type of your response." -PlutoTeachingTools.wrong_type_text_str(lang::Lang, var, type) where {Lang <: English} = md"The type of $var should be $type" -PlutoTeachingTools.func_not_defined_str(lang::Lang) where {Lang <: English} = "Oopsie!" -PlutoTeachingTools.func_not_defined_text_str(func_name, lang::Lang) where {Lang <: English} = md"Make sure that you define a function called **$(Markdown.Code(string(func_name)))**" -PlutoTeachingTools.var_not_defined_str(lang::Lang) where {Lang <: English} = "Oopsie!" -PlutoTeachingTools.var_not_defined_text_str(variable_name, lang::Lang) where {Lang <: English} = md"Make sure that you define a variable called **$(Markdown.Code(string(variable_name)))**" -PlutoTeachingTools.keep_working_str(lang::Lang) where {Lang <: English} = "Keep working on it!" -PlutoTeachingTools.keep_working_text_str(lang::Lang) where {Lang <: English} = md"The answer is not quite right." -PlutoTeachingTools.keep_working_update_str(var, lang::Lang) where {Lang <: English} = md"Make sure to update the cell setting $var." -PlutoTeachingTools.yays(lang::Lang) where {Lang <: English} = [md"Great!", md"Yay ❤", md"Great! 🎉", md"Well done!", md"Keep it up!", md"Good job!", md"Awesome!", md"You got the right answer!", md"Let's move on to the next part."] -PlutoTeachingTools.correct_str(lang::Lang) where {Lang <: English} = "Got it!" -PlutoTeachingTools.todo_str(lang::Lang) where {Lang <: English} = "TODO" - -PlutoTeachingTools.check_type_isa_missing_text_str(sym, lang::Lang) where {Lang <: English} = md"The variable $sym is still set to missing." -PlutoTeachingTools.check_type_isa_wrong_type_text_str(sym, lang::Lang) where {Lang <: English} = "The type of $sym is not correct. It should be <: " -PlutoTeachingTools.check_type_isa_wrong_type_one_of_text_str(lang::Lang) where {Lang <: English} = "one of" -PlutoTeachingTools.check_type_isa_wrong_type_or_text_str(lang::Lang) where {Lang <: English} = "or" -PlutoTeachingTools.check_type_isa_not_missing_text_str(sym, lang::Lang) where {Lang <: English} = md"$sym has the correct type." -PlutoTeachingTools.check_type_isa_type_error_str(sym, lang::Lang) where {Lang <: English} = "Type Error" - -PlutoTeachingTools.check_type_eq_missing_text_str(sym, lang::Lang) where {Lang <: English} = md"The variable $sym is still set to missing." -PlutoTeachingTools.check_type_eq_wrong_type_single_text_str(sym, type, lang::Lang) where {Lang <: English} = "The type of $sym should be $type." -PlutoTeachingTools.check_type_eq_wrong_type_multi_text_str(sym, lang::Lang) where {Lang <: English} = "The type of $sym should be one of " -PlutoTeachingTools.check_type_eq_type_error_str(lang::Lang) where {Lang <: English} = "Type Error" -PlutoTeachingTools.check_type_eq_correct_str(sym, lang::Lang) where {Lang <: English} = md"$sym has the correct type." +PlutoTeachingTools.hint_str(lang::Lang) where {Lang<:English} = "Hint" +PlutoTeachingTools.tip_str(lang::Lang) where {Lang<:English} = "Tip" +function PlutoTeachingTools.protip_invite_str(lang::Lang) where {Lang<:English} + return "Curious to learn more?" +end +PlutoTeachingTools.protip_boxlabel_str(lang::Lang) where {Lang<:English} = "Pro Tip" +function PlutoTeachingTools.answer_invite_str(lang::Lang) where {Lang<:English} + return "Want to see the answer?" +end +PlutoTeachingTools.answer_boxlabel_str(lang::Lang) where {Lang<:English} = "Answer" +PlutoTeachingTools.almost_str(lang::Lang) where {Lang<:English} = "Almost there!" +PlutoTeachingTools.warning_box_str(lang::Lang) where {Lang<:English} = "Warning:" +PlutoTeachingTools.question_box_str(lang::Lang) where {Lang<:English} = "Question:" +PlutoTeachingTools.danger_str(lang::Lang) where {Lang<:English} = "Beware!" +PlutoTeachingTools.keyconcept_str(lang::Lang) where {Lang<:English} = "🎯 Key concept" +PlutoTeachingTools.still_missing_str(lang::Lang) where {Lang<:English} = "Missing Response" +function PlutoTeachingTools.still_missing_text_str(lang::Lang) where {Lang<:English} + md"Replace `missing` with your answer." +end +PlutoTeachingTools.still_nothing_str(lang::Lang) where {Lang<:English} = "Here we go!" +function PlutoTeachingTools.still_nothing_text_str(lang::Lang) where {Lang<:English} + md"Replace `nothing` with your answer." +end +PlutoTeachingTools.wrong_type_str(lang::Lang) where {Lang<:English} = "Type Error" +function PlutoTeachingTools.wrong_type_text_str(lang::Lang) where {Lang<:English} + md"Check the type of your response." +end +function PlutoTeachingTools.wrong_type_text_str(lang::Lang, var, type) where {Lang<:English} + md"The type of $var should be $type" +end +PlutoTeachingTools.func_not_defined_str(lang::Lang) where {Lang<:English} = "Oopsie!" +function PlutoTeachingTools.func_not_defined_text_str( + func_name, lang::Lang +) where {Lang<:English} + md"Make sure that you define a function called **$(Markdown.Code(string(func_name)))**" +end +PlutoTeachingTools.var_not_defined_str(lang::Lang) where {Lang<:English} = "Oopsie!" +function PlutoTeachingTools.var_not_defined_text_str( + variable_name, lang::Lang +) where {Lang<:English} + md"Make sure that you define a variable called **$(Markdown.Code(string(variable_name)))**" +end +function PlutoTeachingTools.keep_working_str(lang::Lang) where {Lang<:English} + return "Keep working on it!" +end +function PlutoTeachingTools.keep_working_text_str(lang::Lang) where {Lang<:English} + md"The answer is not quite right." +end +function PlutoTeachingTools.keep_working_update_str(var, lang::Lang) where {Lang<:English} + md"Make sure to update the cell setting $var." +end +function PlutoTeachingTools.yays(lang::Lang) where {Lang<:English} + return [ + md"Great!", + md"Yay ❤", + md"Great! 🎉", + md"Well done!", + md"Keep it up!", + md"Good job!", + md"Awesome!", + md"You got the right answer!", + md"Let's move on to the next part.", + ] +end +PlutoTeachingTools.correct_str(lang::Lang) where {Lang<:English} = "Got it!" +PlutoTeachingTools.todo_str(lang::Lang) where {Lang<:English} = "TODO" + +function PlutoTeachingTools.check_type_isa_missing_text_str( + sym, lang::Lang +) where {Lang<:English} + md"The variable $sym is still set to missing." +end +function PlutoTeachingTools.check_type_isa_wrong_type_text_str( + sym, lang::Lang +) where {Lang<:English} + return "The type of $sym is not correct. It should be <: " +end +function PlutoTeachingTools.check_type_isa_wrong_type_one_of_text_str( + lang::Lang +) where {Lang<:English} + return "one of" +end +function PlutoTeachingTools.check_type_isa_wrong_type_or_text_str( + lang::Lang +) where {Lang<:English} + return "or" +end +function PlutoTeachingTools.check_type_isa_not_missing_text_str( + sym, lang::Lang +) where {Lang<:English} + md"$sym has the correct type." +end +function PlutoTeachingTools.check_type_isa_type_error_str( + sym, lang::Lang +) where {Lang<:English} + return "Type Error" +end + +function PlutoTeachingTools.check_type_eq_missing_text_str( + sym, lang::Lang +) where {Lang<:English} + md"The variable $sym is still set to missing." +end +function PlutoTeachingTools.check_type_eq_wrong_type_single_text_str( + sym, type, lang::Lang +) where {Lang<:English} + return "The type of $sym should be $type." +end +function PlutoTeachingTools.check_type_eq_wrong_type_multi_text_str( + sym, lang::Lang +) where {Lang<:English} + return "The type of $sym should be one of " +end +function PlutoTeachingTools.check_type_eq_type_error_str(lang::Lang) where {Lang<:English} + return "Type Error" +end +function PlutoTeachingTools.check_type_eq_correct_str(sym, lang::Lang) where {Lang<:English} + md"$sym has the correct type." +end # other.jl -PlutoTeachingTools.full_width_mode_str(lang::Lang) where {Lang <: English} = "Full Width Mode" +PlutoTeachingTools.full_width_mode_str(lang::Lang) where {Lang<:English} = "Full Width Mode" # present.jl -PlutoTeachingTools.present_str(lang::Lang) where {Lang <: English} = "present" -PlutoTeachingTools.present_mode_str(lang::Lang) where {Lang <: English} = "Present Mode" +PlutoTeachingTools.present_str(lang::Lang) where {Lang<:English} = "present" +PlutoTeachingTools.present_mode_str(lang::Lang) where {Lang<:English} = "Present Mode" end diff --git a/src/i18n/german.jl b/src/i18n/german.jl index e276041..3272413 100644 --- a/src/i18n/german.jl +++ b/src/i18n/german.jl @@ -4,67 +4,195 @@ using Markdown using ..PlutoTeachingTools -abstract type German <: AbstractLanguage end +abstract type German <: AbstractLanguage end struct GermanGermanyFormal <: German end struct GermanGermanyColloquial <: German end GermanGermany = GermanGermanyFormal # computational_thinking.jl -PlutoTeachingTools.hint_str(lang::Lang) where {Lang <: German} = "Hinweis" -PlutoTeachingTools.tip_str(lang::Lang) where {Lang <: German} = "Tipp" -PlutoTeachingTools.protip_invite_str(lang::Lang) where {Lang <: German} = "Neugierig auf mehr?" -PlutoTeachingTools.protip_boxlabel_str(lang::Lang) where {Lang <: German} = "Profi-Tipp" -PlutoTeachingTools.answer_invite_str(lang::Lang) where {Lang <: German} = "Willst du die Antwort sehen?" -PlutoTeachingTools.answer_boxlabel_str(lang::Lang) where {Lang <: German} = "Antwort" -PlutoTeachingTools.almost_str(lang::Lang) where {Lang <: German} = "Fast am Ziel!" -PlutoTeachingTools.warning_box_str(lang::Lang) where {Lang <: German} = "Warnung:" -PlutoTeachingTools.question_box_str(lang::Lang) where {Lang <: German} = "Frage:" -PlutoTeachingTools.danger_str(lang::Lang) where {Lang <: German} = "Achtung!" -PlutoTeachingTools.keyconcept_str(lang::Lang) where {Lang <: German} = "🎯 Schlüsselkonzept" -PlutoTeachingTools.still_missing_str(lang::Lang) where {Lang <: German} = "Fehlende Antwort" -PlutoTeachingTools.still_missing_text_str(lang::Lang) where {Lang <: GermanGermanyFormal} = md"Ersetzen Sie `missing` mit Ihrer Antwort." -PlutoTeachingTools.still_missing_text_str(lang::Lang) where {Lang <: GermanGermanyColloquial} = md"Ersetze `missing` mit deiner Antwort." -PlutoTeachingTools.still_nothing_str(lang::Lang) where {Lang <: German} = "Fehlende Antwort" -PlutoTeachingTools.still_nothing_text_str(lang::Lang) where {Lang <: GermanGermanyFormal} = md"Ersetzen Sie `nothing` mit Ihrer Antwort." -PlutoTeachingTools.still_nothing_text_str(lang::Lang) where {Lang <: GermanGermanyColloquial} = md"Ersetze `nothing` mit deiner Antwort." -PlutoTeachingTools.wrong_type_str(lang::Lang) where {Lang <: German} = "Typfehler" -PlutoTeachingTools.wrong_type_text_str(lang::Lang) where {Lang <: GermanGermanyFormal} = md"Kontrollieren Sie den Typ Ihrer Antwort." -PlutoTeachingTools.wrong_type_text_str(lang::Lang) where {Lang <: GermanGermanyColloquial} = md"Kontrolliere den Typ deiner Antwort." -PlutoTeachingTools.wrong_type_text_str(lang::Lang, var, type) where {Lang <: German} = md"Der Typ von $var sollte $type sein." -PlutoTeachingTools.func_not_defined_str(lang::Lang) where {Lang <: German} = "Uups!" -PlutoTeachingTools.func_not_defined_text_str(func_name, lang::Lang) where {Lang <: GermanGermanyFormal} = md"Stellen Sie sicher, eine Funktion mit dem Namen **$(Markdown.Code(string(func_name)))** zu definieren." -PlutoTeachingTools.func_not_defined_text_str(func_name, lang::Lang) where {Lang <: GermanGermanyColloquial} = md"Stelle sicher, eine Funktion mit dem Namen **$(Markdown.Code(string(func_name)))** zu definieren." -PlutoTeachingTools.var_not_defined_str(lang::Lang) where {Lang <: German} = "Uups!" -PlutoTeachingTools.var_not_defined_text_str(variable_name, lang::Lang) where {Lang <: GermanGermanyFormal} = md"Stellen Sie sicher, eine Variable mit dem Namen **$(Markdown.Code(string(variable_name)))** zu definieren." -PlutoTeachingTools.var_not_defined_text_str(variable_name, lang::Lang) where {Lang <: GermanGermanyColloquial} = md"Stelle sicher, eine Variable mit dem Namen **$(Markdown.Code(string(variable_name)))** zu definieren." -PlutoTeachingTools.keep_working_str(lang::Lang) where {Lang <: GermanGermanyFormal} = "Versuchen Sie es weiter!" -PlutoTeachingTools.keep_working_str(lang::Lang) where {Lang <: GermanGermanyColloquial} = "Versuch es weiter!" -PlutoTeachingTools.keep_working_text_str(lang::Lang) where {Lang <: German} = md"Die Antwort ist noch nicht ganz richtig." -PlutoTeachingTools.keep_working_update_str(var, lang::Lang) where {Lang <: GermanGermanyFormal} = md"Stellen Sie sicher, dass die Zelle mit der Variable $var erneut evaluiert wird." -PlutoTeachingTools.keep_working_update_str(var, lang::Lang) where {Lang <: GermanGermanyColloquial} = md"Stelle sicher, dass die Zelle mit der Variable $var erneut evaluiert wird." -PlutoTeachingTools.yays(lang::Lang) where {Lang <: GermanGermanyFormal} = [md"Großartig!", md"Juchu ❤", md"Großartig! 🎉", md"Gut gemacht!", md"Weiter so!", md"Gute Arbeit!", md"Super!", md"Ihre Antwort ist richtig!", md"Weiter geht's mit der nächsten Antwort."] -PlutoTeachingTools.yays(lang::Lang) where {Lang <: GermanGermanyColloquial} = [md"Großartig!", md"Juchu ❤", md"Großartig! 🎉", md"Gut gemacht!", md"Weiter so!", md"Gute Arbeit!", md"Super!", md"Deine Antwort ist richtig!", md"Weiter geht's mit der nächsten Antwort."] -PlutoTeachingTools.correct_str(lang::Lang) where {Lang <: German} = "Richtig!" -PlutoTeachingTools.todo_str(lang::Lang) where {Lang <: German} = "TO-DO" +PlutoTeachingTools.hint_str(lang::Lang) where {Lang<:German} = "Hinweis" +PlutoTeachingTools.tip_str(lang::Lang) where {Lang<:German} = "Tipp" +function PlutoTeachingTools.protip_invite_str(lang::Lang) where {Lang<:German} + return "Neugierig auf mehr?" +end +PlutoTeachingTools.protip_boxlabel_str(lang::Lang) where {Lang<:German} = "Profi-Tipp" +function PlutoTeachingTools.answer_invite_str(lang::Lang) where {Lang<:German} + return "Willst du die Antwort sehen?" +end +PlutoTeachingTools.answer_boxlabel_str(lang::Lang) where {Lang<:German} = "Antwort" +PlutoTeachingTools.almost_str(lang::Lang) where {Lang<:German} = "Fast am Ziel!" +PlutoTeachingTools.warning_box_str(lang::Lang) where {Lang<:German} = "Warnung:" +PlutoTeachingTools.question_box_str(lang::Lang) where {Lang<:German} = "Frage:" +PlutoTeachingTools.danger_str(lang::Lang) where {Lang<:German} = "Achtung!" +PlutoTeachingTools.keyconcept_str(lang::Lang) where {Lang<:German} = "🎯 Schlüsselkonzept" +PlutoTeachingTools.still_missing_str(lang::Lang) where {Lang<:German} = "Fehlende Antwort" +function PlutoTeachingTools.still_missing_text_str( + lang::Lang +) where {Lang<:GermanGermanyFormal} + md"Ersetzen Sie `missing` mit Ihrer Antwort." +end +function PlutoTeachingTools.still_missing_text_str( + lang::Lang +) where {Lang<:GermanGermanyColloquial} + md"Ersetze `missing` mit deiner Antwort." +end +PlutoTeachingTools.still_nothing_str(lang::Lang) where {Lang<:German} = "Fehlende Antwort" +function PlutoTeachingTools.still_nothing_text_str( + lang::Lang +) where {Lang<:GermanGermanyFormal} + md"Ersetzen Sie `nothing` mit Ihrer Antwort." +end +function PlutoTeachingTools.still_nothing_text_str( + lang::Lang +) where {Lang<:GermanGermanyColloquial} + md"Ersetze `nothing` mit deiner Antwort." +end +PlutoTeachingTools.wrong_type_str(lang::Lang) where {Lang<:German} = "Typfehler" +function PlutoTeachingTools.wrong_type_text_str( + lang::Lang +) where {Lang<:GermanGermanyFormal} + md"Kontrollieren Sie den Typ Ihrer Antwort." +end +function PlutoTeachingTools.wrong_type_text_str( + lang::Lang +) where {Lang<:GermanGermanyColloquial} + md"Kontrolliere den Typ deiner Antwort." +end +function PlutoTeachingTools.wrong_type_text_str(lang::Lang, var, type) where {Lang<:German} + md"Der Typ von $var sollte $type sein." +end +PlutoTeachingTools.func_not_defined_str(lang::Lang) where {Lang<:German} = "Uups!" +function PlutoTeachingTools.func_not_defined_text_str( + func_name, lang::Lang +) where {Lang<:GermanGermanyFormal} + md"Stellen Sie sicher, eine Funktion mit dem Namen **$(Markdown.Code(string(func_name)))** zu definieren." +end +function PlutoTeachingTools.func_not_defined_text_str( + func_name, lang::Lang +) where {Lang<:GermanGermanyColloquial} + md"Stelle sicher, eine Funktion mit dem Namen **$(Markdown.Code(string(func_name)))** zu definieren." +end +PlutoTeachingTools.var_not_defined_str(lang::Lang) where {Lang<:German} = "Uups!" +function PlutoTeachingTools.var_not_defined_text_str( + variable_name, lang::Lang +) where {Lang<:GermanGermanyFormal} + md"Stellen Sie sicher, eine Variable mit dem Namen **$(Markdown.Code(string(variable_name)))** zu definieren." +end +function PlutoTeachingTools.var_not_defined_text_str( + variable_name, lang::Lang +) where {Lang<:GermanGermanyColloquial} + md"Stelle sicher, eine Variable mit dem Namen **$(Markdown.Code(string(variable_name)))** zu definieren." +end +function PlutoTeachingTools.keep_working_str(lang::Lang) where {Lang<:GermanGermanyFormal} + return "Versuchen Sie es weiter!" +end +function PlutoTeachingTools.keep_working_str( + lang::Lang +) where {Lang<:GermanGermanyColloquial} + return "Versuch es weiter!" +end +function PlutoTeachingTools.keep_working_text_str(lang::Lang) where {Lang<:German} + md"Die Antwort ist noch nicht ganz richtig." +end +function PlutoTeachingTools.keep_working_update_str( + var, lang::Lang +) where {Lang<:GermanGermanyFormal} + md"Stellen Sie sicher, dass die Zelle mit der Variable $var erneut evaluiert wird." +end +function PlutoTeachingTools.keep_working_update_str( + var, lang::Lang +) where {Lang<:GermanGermanyColloquial} + md"Stelle sicher, dass die Zelle mit der Variable $var erneut evaluiert wird." +end +function PlutoTeachingTools.yays(lang::Lang) where {Lang<:GermanGermanyFormal} + return [ + md"Großartig!", + md"Juchu ❤", + md"Großartig! 🎉", + md"Gut gemacht!", + md"Weiter so!", + md"Gute Arbeit!", + md"Super!", + md"Ihre Antwort ist richtig!", + md"Weiter geht's mit der nächsten Antwort.", + ] +end +function PlutoTeachingTools.yays(lang::Lang) where {Lang<:GermanGermanyColloquial} + return [ + md"Großartig!", + md"Juchu ❤", + md"Großartig! 🎉", + md"Gut gemacht!", + md"Weiter so!", + md"Gute Arbeit!", + md"Super!", + md"Deine Antwort ist richtig!", + md"Weiter geht's mit der nächsten Antwort.", + ] +end +PlutoTeachingTools.correct_str(lang::Lang) where {Lang<:German} = "Richtig!" +PlutoTeachingTools.todo_str(lang::Lang) where {Lang<:German} = "TO-DO" -PlutoTeachingTools.check_type_isa_missing_text_str(sym, lang::Lang) where {Lang <: German} = md"Die Variable $sym ist immer noch `missing`." -PlutoTeachingTools.check_type_isa_wrong_type_text_str(sym, lang::Lang) where {Lang <: German} = "Der Typ von $sym ist nicht richtig. Richtig wäre <: " -PlutoTeachingTools.check_type_isa_wrong_type_one_of_text_str(lang::Lang) where {Lang <: German} = "einer von" -PlutoTeachingTools.check_type_isa_wrong_type_or_text_str(lang::Lang) where {Lang <: German} = "oder" -PlutoTeachingTools.check_type_isa_not_missing_text_str(sym, lang::Lang) where {Lang <: German} = md"$sym hat den korrekten Typ." -PlutoTeachingTools.check_type_isa_type_error_str(sym, lang::Lang) where {Lang <: German} = "Typfehler" +function PlutoTeachingTools.check_type_isa_missing_text_str( + sym, lang::Lang +) where {Lang<:German} + md"Die Variable $sym ist immer noch `missing`." +end +function PlutoTeachingTools.check_type_isa_wrong_type_text_str( + sym, lang::Lang +) where {Lang<:German} + return "Der Typ von $sym ist nicht richtig. Richtig wäre <: " +end +function PlutoTeachingTools.check_type_isa_wrong_type_one_of_text_str( + lang::Lang +) where {Lang<:German} + return "einer von" +end +function PlutoTeachingTools.check_type_isa_wrong_type_or_text_str( + lang::Lang +) where {Lang<:German} + return "oder" +end +function PlutoTeachingTools.check_type_isa_not_missing_text_str( + sym, lang::Lang +) where {Lang<:German} + md"$sym hat den korrekten Typ." +end +function PlutoTeachingTools.check_type_isa_type_error_str( + sym, lang::Lang +) where {Lang<:German} + return "Typfehler" +end -PlutoTeachingTools.check_type_eq_missing_text_str(sym, lang::Lang) where {Lang <: German} = md"Die Variable $sym ist immer noch `missing`." -PlutoTeachingTools.check_type_eq_wrong_type_single_text_str(sym, type, lang::Lang) where {Lang <: German} = "Der Typ von $sym sollte $type sein." -PlutoTeachingTools.check_type_eq_wrong_type_multi_text_str(sym, lang::Lang) where {Lang <: German} = "Der Typ von $sym sollte einer der folgenden sein: " -PlutoTeachingTools.check_type_eq_type_error_str(lang::Lang) where {Lang <: German} = "Typfehler" -PlutoTeachingTools.check_type_eq_correct_str(sym, lang::Lang) where {Lang <: German} = md"$sym hat den korrekten Typ." +function PlutoTeachingTools.check_type_eq_missing_text_str( + sym, lang::Lang +) where {Lang<:German} + md"Die Variable $sym ist immer noch `missing`." +end +function PlutoTeachingTools.check_type_eq_wrong_type_single_text_str( + sym, type, lang::Lang +) where {Lang<:German} + return "Der Typ von $sym sollte $type sein." +end +function PlutoTeachingTools.check_type_eq_wrong_type_multi_text_str( + sym, lang::Lang +) where {Lang<:German} + return "Der Typ von $sym sollte einer der folgenden sein: " +end +function PlutoTeachingTools.check_type_eq_type_error_str(lang::Lang) where {Lang<:German} + return "Typfehler" +end +function PlutoTeachingTools.check_type_eq_correct_str(sym, lang::Lang) where {Lang<:German} + md"$sym hat den korrekten Typ." +end # other.jl -PlutoTeachingTools.full_width_mode_str(lang::Lang) where {Lang <: German} = "Modus \"Volle Breite\"" +function PlutoTeachingTools.full_width_mode_str(lang::Lang) where {Lang<:German} + return "Modus \"Volle Breite\"" +end # present.jl -PlutoTeachingTools.present_str(lang::Lang) where {Lang <: German} = "präsentieren" -PlutoTeachingTools.present_mode_str(lang::Lang) where {Lang <: German} = "Präsentationsmodus" +PlutoTeachingTools.present_str(lang::Lang) where {Lang<:German} = "präsentieren" +PlutoTeachingTools.present_mode_str(lang::Lang) where {Lang<:German} = "Präsentationsmodus" end diff --git a/src/i18n/i18n.jl b/src/i18n/i18n.jl index d9843d6..58b0442 100644 --- a/src/i18n/i18n.jl +++ b/src/i18n/i18n.jl @@ -3,54 +3,136 @@ export preferred_text abstract type AbstractLanguage end # computational_thinking.jl -hint_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -tip_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -answer_invite_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -answer_boxlabel_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -protip_invite_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -protip_boxlabel_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -almost_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -warning_box_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -question_box_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -keyconcept_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -danger_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -still_missing_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -still_missing_text_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -still_nothing_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -still_nothing_text_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -wrong_type_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -wrong_type_text_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -wrong_type_text_str(lang::Lang, var, type) where {Lang <: AbstractLanguage} = @error "Please define a translation." -func_not_defined_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -func_not_defined_text_str(func_name, lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -var_not_defined_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -var_not_defined_text_str(variable_name, lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -keep_working_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -keep_working_text_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -keep_working_update_str(var, lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -yays(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -correct_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -todo_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." - -check_type_isa_missing_text_str(sym, lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -check_type_isa_wrong_type_text_str(sym, lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -check_type_isa_wrong_type_one_of_text_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -check_type_isa_wrong_type_or_text_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -check_type_isa_not_missing_text_str(sym, lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -check_type_isa_type_error_str(sym, lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." - -check_type_eq_missing_text_str(sym, lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -check_type_eq_wrong_type_single_text_str(sym, type, lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -check_type_eq_wrong_type_multi_text_str(sym, lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -check_type_eq_type_error_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -check_type_eq_correct_str(sym, lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." +hint_str(lang::Lang) where {Lang<:AbstractLanguage} = @error "Please define a translation." +tip_str(lang::Lang) where {Lang<:AbstractLanguage} = @error "Please define a translation." +function answer_invite_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function answer_boxlabel_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function protip_invite_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function protip_boxlabel_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function almost_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function warning_box_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function question_box_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function keyconcept_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function danger_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function still_missing_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function still_missing_text_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function still_nothing_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function still_nothing_text_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function wrong_type_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function wrong_type_text_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function wrong_type_text_str(lang::Lang, var, type) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function func_not_defined_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function func_not_defined_text_str(func_name, lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function var_not_defined_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function var_not_defined_text_str(variable_name, lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function keep_working_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function keep_working_text_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function keep_working_update_str(var, lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +yays(lang::Lang) where {Lang<:AbstractLanguage} = @error "Please define a translation." +function correct_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +todo_str(lang::Lang) where {Lang<:AbstractLanguage} = @error "Please define a translation." + +function check_type_isa_missing_text_str(sym, lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function check_type_isa_wrong_type_text_str(sym, lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function check_type_isa_wrong_type_one_of_text_str( + lang::Lang +) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function check_type_isa_wrong_type_or_text_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function check_type_isa_not_missing_text_str(sym, lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function check_type_isa_type_error_str(sym, lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end + +function check_type_eq_missing_text_str(sym, lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function check_type_eq_wrong_type_single_text_str( + sym, type, lang::Lang +) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function check_type_eq_wrong_type_multi_text_str( + sym, lang::Lang +) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function check_type_eq_type_error_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function check_type_eq_correct_str(sym, lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end # other.jl -full_width_mode_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." +function full_width_mode_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end # present.jl -present_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." -present_mode_str(lang::Lang) where {Lang <: AbstractLanguage} = @error "Please define a translation." +function present_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end +function present_mode_str(lang::Lang) where {Lang<:AbstractLanguage} + @error "Please define a translation." +end # Language Options include("english.jl") @@ -65,81 +147,88 @@ include("chinese.jl") import .PTTChinese: ChineseZH const languages_registered = Ref{Dict{String,AbstractLanguage}}( - Dict( "en" => PTTEnglish.EnglishUS(), - "en_us" => PTTEnglish.EnglishUS(), - "de" => PTTGerman.GermanGermany(), - "de_colloq" => PTTGerman.GermanGermanyColloquial(), - "de_de" => PTTGerman.GermanGermany(), - "de_de_colloq" => PTTGerman.GermanGermanyColloquial(), - "ru" => PTTRussian.RussianRU(), - "es" => PTTSpanish.SpanishES(), - "es_colloq" => PTTSpanish.SpanishColloquial(), - "es_es" => PTTSpanish.SpanishES(), - "es_es_colloq" => PTTSpanish.SpanishColloquial(), - "zh" => PTTChinese.ChineseZH(), - )) + Dict( + "en" => PTTEnglish.EnglishUS(), + "en_us" => PTTEnglish.EnglishUS(), + "de" => PTTGerman.GermanGermany(), + "de_colloq" => PTTGerman.GermanGermanyColloquial(), + "de_de" => PTTGerman.GermanGermany(), + "de_de_colloq" => PTTGerman.GermanGermanyColloquial(), + "ru" => PTTRussian.RussianRU(), + "es" => PTTSpanish.SpanishES(), + "es_colloq" => PTTSpanish.SpanishColloquial(), + "es_es" => PTTSpanish.SpanishES(), + "es_es_colloq" => PTTSpanish.SpanishColloquial(), + "zh" => PTTChinese.ChineseZH(), + ), +) const language_codes_registered = Ref{Dict{AbstractLanguage,Vector{String}}}( - Dict( PTTEnglish.EnglishUS() => ["en","en_us"], - PTTGerman.GermanGermany() => ["de","de_de"], - PTTGerman.GermanGermanyColloquial() => ["de_colloq", "de_de_colloq"], - PTTRussian.RussianRU() => ["ru","ru_ru"], - PTTSpanish.SpanishES() => ["es", "es_es"], - PTTSpanish.SpanishColloquial() => ["es_colloq", "es_es_colloq"], - PTTChinese.ChineseZH() => ["zh", "zh_cn"] - )) + Dict( + PTTEnglish.EnglishUS() => ["en", "en_us"], + PTTGerman.GermanGermany() => ["de", "de_de"], + PTTGerman.GermanGermanyColloquial() => ["de_colloq", "de_de_colloq"], + PTTRussian.RussianRU() => ["ru", "ru_ru"], + PTTSpanish.SpanishES() => ["es", "es_es"], + PTTSpanish.SpanishColloquial() => ["es_colloq", "es_es_colloq"], + PTTChinese.ChineseZH() => ["zh", "zh_cn"], + ), +) # Allow users to register additional languages -function register_language!(str::AbstractString, lang::Lang) where { Lang <: AbstractLanguage } - languages_registered[][str] = lang - language_codes_registered[][lang] = [str] +function register_language!(str::AbstractString, lang::Lang) where {Lang<:AbstractLanguage} + languages_registered[][str] = lang + return language_codes_registered[][lang] = [str] end - -function register_language!(strs::AVS, lang::Lang) where {AS<:AbstractString, AVS<:AbstractVector{AS}, Lang<:AbstractLanguage} - for str in strs - languages_registered[][str] = lang - end - language_codes_registered[][lang] = strs +function register_language!( + strs::AVS, lang::Lang +) where {AS<:AbstractString,AVS<:AbstractVector{AS},Lang<:AbstractLanguage} + for str in strs + languages_registered[][str] = lang + end + return language_codes_registered[][lang] = strs end # Pick language from language code # see https://www.science.co.il/language/Locale-codes.php function get_language(str::AbstractString) - str = replace(lowercase(str), '-'=>'_') - m = match(r"^(\w+)\.",str) - key = isnothing(m) ? str : first(m.captures) - if !haskey(languages_registered[],key) - # @info "Sorry, PlutoTeachingTools doesn't include that language." - nothing # PTTEnglish.EnglishUS() - else - languages_registered[][key] - end + str = replace(lowercase(str), '-' => '_') + m = match(r"^(\w+)\.", str) + key = isnothing(m) ? str : first(m.captures) + if !haskey(languages_registered[], key) + # @info "Sorry, PlutoTeachingTools doesn't include that language." + nothing # PTTEnglish.EnglishUS() + else + languages_registered[][key] + end end # Keeping around until new version is better tested function get_language_old(str::AbstractString) - if contains(str,r"^en") - PTTEnglish.EnglishUS() - elseif contains(str,r"^de") - PTTGerman.GermanGermany() - elseif contains(str,r"^es") - PTTSpanish.SpanishFormal() - else # Sorry, we don't have your language yet. - # @info "Sorry, PlutoTeachingTools doesn't include that language." - PTTEnglish.EnglishUS() - end -end - -function get_language_from_env(; default::Lang = PTTEnglish.EnglishUS() ) where { Lang<:AbstractLanguage } - lang = default - if @isdefined(ENV) && haskey(ENV,"LANG") - lang = get_language(ENV["LANG"]) - end - if isnothing(lang) - lang = default - end - return lang + if contains(str, r"^en") + PTTEnglish.EnglishUS() + elseif contains(str, r"^de") + PTTGerman.GermanGermany() + elseif contains(str, r"^es") + PTTSpanish.SpanishFormal() + else # Sorry, we don't have your language yet. + # @info "Sorry, PlutoTeachingTools doesn't include that language." + PTTEnglish.EnglishUS() + end +end + +function get_language_from_env(; + default::Lang=PTTEnglish.EnglishUS() +) where {Lang<:AbstractLanguage} + lang = default + if @isdefined(ENV) && haskey(ENV, "LANG") + lang = get_language(ENV["LANG"]) + end + if isnothing(lang) + lang = default + end + return lang end # Keep track of language to use @@ -147,7 +236,7 @@ end const default_language = Ref{AbstractLanguage}(get_language_from_env()) function set_language!(lang::AbstractLanguage) - global default_language[] = lang + return global default_language[] = lang end """ @@ -159,17 +248,17 @@ If text for current language is not provided, then returns first value of named Examples: `preferred_text( (en="Hello", de="Hallo") )` """ -function preferred_text(nt::NamedTuple; warn::Bool = false, lang::Lang = default_language[]) where { Lang <: AbstractLanguage } - lang_codes_w_text = string.(keys(nt)) - mask = map(t->isa(lang,t), typeof.(get_language.(lang_codes_w_text))) - if !any(mask) - if warn - @warn "`preferred_text` was not provided with text for current language." - end - return first(nt) - else - nt[findfirst(mask)] - end +function preferred_text( + nt::NamedTuple; warn::Bool=false, lang::Lang=default_language[] +) where {Lang<:AbstractLanguage} + lang_codes_w_text = string.(keys(nt)) + mask = map(t -> isa(lang, t), typeof.(get_language.(lang_codes_w_text))) + if !any(mask) + if warn + @warn "`preferred_text` was not provided with text for current language." + end + return first(nt) + else + nt[findfirst(mask)] + end end - - diff --git a/src/i18n/russian.jl b/src/i18n/russian.jl index bcd2f0d..488e9df 100644 --- a/src/i18n/russian.jl +++ b/src/i18n/russian.jl @@ -4,57 +4,141 @@ using Markdown using ..PlutoTeachingTools -abstract type Russian <: AbstractLanguage end +abstract type Russian <: AbstractLanguage end struct RussianRU <: Russian end # computational_thinking.jl -PlutoTeachingTools.hint_str(lang::Lang) where {Lang <: Russian} = "Подсказка" -PlutoTeachingTools.tip_str(lang::Lang) where {Lang <: Russian} = "Совет" -PlutoTeachingTools.protip_invite_str(lang::Lang) where {Lang <: Russian} = "Хотите узнать больше?" -PlutoTeachingTools.protip_boxlabel_str(lang::Lang) where {Lang <: Russian} = "Совет профессионала" -PlutoTeachingTools.answer_invite_str(lang::Lang) where {Lang <: Russian} = "Хотите посмотреть ответ?" -PlutoTeachingTools.answer_boxlabel_str(lang::Lang) where {Lang <: Russian} = "Ответ" -PlutoTeachingTools.almost_str(lang::Lang) where {Lang <: Russian} = "Почти правильно!" -PlutoTeachingTools.warning_box_str(lang::Lang) where {Lang <: Russian} = "Внимание:" -PlutoTeachingTools.question_box_str(lang::Lang) where {Lang <: Russian} = "Вопрос:" -PlutoTeachingTools.danger_str(lang::Lang) where {Lang <: Russian} = "Осторожно!" -PlutoTeachingTools.keyconcept_str(lang::Lang) where {Lang <: Russian} = "🎯 Ключевое понятие" -PlutoTeachingTools.still_missing_str(lang::Lang) where {Lang <: Russian} = "Отсутствующий ответ" -PlutoTeachingTools.still_missing_text_str(lang::Lang) where {Lang <: Russian} = md"Замените `missing` на ваш ответ." -PlutoTeachingTools.still_nothing_str(lang::Lang) where {Lang <: Russian} = "Начинаем!" -PlutoTeachingTools.still_nothing_text_str(lang::Lang) where {Lang <: Russian} = md"Замените `nothing` на ваш ответ." -PlutoTeachingTools.wrong_type_str(lang::Lang) where {Lang <: Russian} = "Ошибка типа" -PlutoTeachingTools.wrong_type_text_str(lang::Lang) where {Lang <: Russian} = md"Проверьте тип вашего ответа." -PlutoTeachingTools.wrong_type_text_str(lang::Lang, var, type) where {Lang <: Russian} = md"Тип $var должен быть $type" -PlutoTeachingTools.func_not_defined_str(lang::Lang) where {Lang <: Russian} = "Ой!" -PlutoTeachingTools.func_not_defined_text_str(func_name, lang::Lang) where {Lang <: Russian} = md"Убедитесь, что вы определили функцию под названием **$(Markdown.Code(string(func_name)))**" -PlutoTeachingTools.var_not_defined_str(lang::Lang) where {Lang <: Russian} = "Ой!" -PlutoTeachingTools.var_not_defined_text_str(variable_name, lang::Lang) where {Lang <: Russian} = md"Убедитесь, что вы определили переменную под названием **$(Markdown.Code(string(variable_name)))**" -PlutoTeachingTools.keep_working_str(lang::Lang) where {Lang <: Russian} = "Продолжайте работу!" -PlutoTeachingTools.keep_working_text_str(lang::Lang) where {Lang <: Russian} = md"Ответ не вполне правильный." -PlutoTeachingTools.keep_working_update_str(var, lang::Lang) where {Lang <: Russian} = md"Обязательно обновите параметр ячейки $var." -PlutoTeachingTools.yays(lang::Lang) where {Lang <: Russian} = [md"Отлично!", md"Ура ❤", md"Здорово! 🎉", md"Молодец!", md"Продолжайте в том же духе!", md"Хорошая работа!", md"Здорово!", md"Получен правильный ответ!", md"Переходим к следующему разделу"] -PlutoTeachingTools.correct_str(lang::Lang) where {Lang <: Russian} = "Получилось!" -PlutoTeachingTools.todo_str(lang::Lang) where {Lang <: Russian} = "НУЖНО СДЕЛАТЬ" - -PlutoTeachingTools.check_type_isa_missing_text_str(sym, lang::Lang) where {Lang <: Russian} = md"Переменная $sym по-прежнему имеет значение `missing`." -PlutoTeachingTools.check_type_isa_wrong_type_text_str(sym, lang::Lang) where {Lang <: Russian} = "Тип $sym задан неверно. Он должен быть <: " -PlutoTeachingTools.check_type_isa_wrong_type_one_of_text_str(lang::Lang) where {Lang <: Russian} = "один из" -PlutoTeachingTools.check_type_isa_wrong_type_or_text_str(lang::Lang) where {Lang <: Russian} = "или" -PlutoTeachingTools.check_type_isa_not_missing_text_str(sym, lang::Lang) where {Lang <: Russian} = md"тип переменной $sym правильный." -PlutoTeachingTools.check_type_isa_type_error_str(sym, lang::Lang) where {Lang <: Russian} = "Ошибка типа" - -PlutoTeachingTools.check_type_eq_missing_text_str(sym, lang::Lang) where {Lang <: Russian} = md"Переменная $sym по-прежнему имеет значение `missing`." -PlutoTeachingTools.check_type_eq_wrong_type_single_text_str(sym, type, lang::Lang) where {Lang <: Russian} = "Тип переменной $sym должен быть $type." -PlutoTeachingTools.check_type_eq_wrong_type_multi_text_str(sym, lang::Lang) where {Lang <: Russian} = "Тип переменной $sym должен быть один из " -PlutoTeachingTools.check_type_eq_type_error_str(lang::Lang) where {Lang <: Russian} = "Ошибка типа" -PlutoTeachingTools.check_type_eq_correct_str(sym, lang::Lang) where {Lang <: Russian} = md"тип переменной $sym правилен." +PlutoTeachingTools.hint_str(lang::Lang) where {Lang<:Russian} = "Подсказка" +PlutoTeachingTools.tip_str(lang::Lang) where {Lang<:Russian} = "Совет" +function PlutoTeachingTools.protip_invite_str(lang::Lang) where {Lang<:Russian} + return "Хотите узнать больше?" +end +function PlutoTeachingTools.protip_boxlabel_str(lang::Lang) where {Lang<:Russian} + return "Совет профессионала" +end +function PlutoTeachingTools.answer_invite_str(lang::Lang) where {Lang<:Russian} + return "Хотите посмотреть ответ?" +end +PlutoTeachingTools.answer_boxlabel_str(lang::Lang) where {Lang<:Russian} = "Ответ" +PlutoTeachingTools.almost_str(lang::Lang) where {Lang<:Russian} = "Почти правильно!" +PlutoTeachingTools.warning_box_str(lang::Lang) where {Lang<:Russian} = "Внимание:" +PlutoTeachingTools.question_box_str(lang::Lang) where {Lang<:Russian} = "Вопрос:" +PlutoTeachingTools.danger_str(lang::Lang) where {Lang<:Russian} = "Осторожно!" +PlutoTeachingTools.keyconcept_str(lang::Lang) where {Lang<:Russian} = "🎯 Ключевое понятие" +function PlutoTeachingTools.still_missing_str(lang::Lang) where {Lang<:Russian} + return "Отсутствующий ответ" +end +function PlutoTeachingTools.still_missing_text_str(lang::Lang) where {Lang<:Russian} + md"Замените `missing` на ваш ответ." +end +PlutoTeachingTools.still_nothing_str(lang::Lang) where {Lang<:Russian} = "Начинаем!" +function PlutoTeachingTools.still_nothing_text_str(lang::Lang) where {Lang<:Russian} + md"Замените `nothing` на ваш ответ." +end +PlutoTeachingTools.wrong_type_str(lang::Lang) where {Lang<:Russian} = "Ошибка типа" +function PlutoTeachingTools.wrong_type_text_str(lang::Lang) where {Lang<:Russian} + md"Проверьте тип вашего ответа." +end +function PlutoTeachingTools.wrong_type_text_str(lang::Lang, var, type) where {Lang<:Russian} + md"Тип $var должен быть $type" +end +PlutoTeachingTools.func_not_defined_str(lang::Lang) where {Lang<:Russian} = "Ой!" +function PlutoTeachingTools.func_not_defined_text_str( + func_name, lang::Lang +) where {Lang<:Russian} + md"Убедитесь, что вы определили функцию под названием **$(Markdown.Code(string(func_name)))**" +end +PlutoTeachingTools.var_not_defined_str(lang::Lang) where {Lang<:Russian} = "Ой!" +function PlutoTeachingTools.var_not_defined_text_str( + variable_name, lang::Lang +) where {Lang<:Russian} + md"Убедитесь, что вы определили переменную под названием **$(Markdown.Code(string(variable_name)))**" +end +function PlutoTeachingTools.keep_working_str(lang::Lang) where {Lang<:Russian} + return "Продолжайте работу!" +end +function PlutoTeachingTools.keep_working_text_str(lang::Lang) where {Lang<:Russian} + md"Ответ не вполне правильный." +end +function PlutoTeachingTools.keep_working_update_str(var, lang::Lang) where {Lang<:Russian} + md"Обязательно обновите параметр ячейки $var." +end +function PlutoTeachingTools.yays(lang::Lang) where {Lang<:Russian} + return [ + md"Отлично!", + md"Ура ❤", + md"Здорово! 🎉", + md"Молодец!", + md"Продолжайте в том же духе!", + md"Хорошая работа!", + md"Здорово!", + md"Получен правильный ответ!", + md"Переходим к следующему разделу", + ] +end +PlutoTeachingTools.correct_str(lang::Lang) where {Lang<:Russian} = "Получилось!" +PlutoTeachingTools.todo_str(lang::Lang) where {Lang<:Russian} = "НУЖНО СДЕЛАТЬ" + +function PlutoTeachingTools.check_type_isa_missing_text_str( + sym, lang::Lang +) where {Lang<:Russian} + md"Переменная $sym по-прежнему имеет значение `missing`." +end +function PlutoTeachingTools.check_type_isa_wrong_type_text_str( + sym, lang::Lang +) where {Lang<:Russian} + return "Тип $sym задан неверно. Он должен быть <: " +end +function PlutoTeachingTools.check_type_isa_wrong_type_one_of_text_str( + lang::Lang +) where {Lang<:Russian} + return "один из" +end +function PlutoTeachingTools.check_type_isa_wrong_type_or_text_str( + lang::Lang +) where {Lang<:Russian} + return "или" +end +function PlutoTeachingTools.check_type_isa_not_missing_text_str( + sym, lang::Lang +) where {Lang<:Russian} + md"тип переменной $sym правильный." +end +function PlutoTeachingTools.check_type_isa_type_error_str( + sym, lang::Lang +) where {Lang<:Russian} + return "Ошибка типа" +end + +function PlutoTeachingTools.check_type_eq_missing_text_str( + sym, lang::Lang +) where {Lang<:Russian} + md"Переменная $sym по-прежнему имеет значение `missing`." +end +function PlutoTeachingTools.check_type_eq_wrong_type_single_text_str( + sym, type, lang::Lang +) where {Lang<:Russian} + return "Тип переменной $sym должен быть $type." +end +function PlutoTeachingTools.check_type_eq_wrong_type_multi_text_str( + sym, lang::Lang +) where {Lang<:Russian} + return "Тип переменной $sym должен быть один из " +end +function PlutoTeachingTools.check_type_eq_type_error_str(lang::Lang) where {Lang<:Russian} + return "Ошибка типа" +end +function PlutoTeachingTools.check_type_eq_correct_str(sym, lang::Lang) where {Lang<:Russian} + md"тип переменной $sym правилен." +end # other.jl -PlutoTeachingTools.full_width_mode_str(lang::Lang) where {Lang <: Russian} = "Режим полной ширины" +function PlutoTeachingTools.full_width_mode_str(lang::Lang) where {Lang<:Russian} + return "Режим полной ширины" +end # present.jl -PlutoTeachingTools.present_str(lang::Lang) where {Lang <: Russian} = "презентация" -PlutoTeachingTools.present_mode_str(lang::Lang) where {Lang <: Russian} = "Режим презентации" +PlutoTeachingTools.present_str(lang::Lang) where {Lang<:Russian} = "презентация" +PlutoTeachingTools.present_mode_str(lang::Lang) where {Lang<:Russian} = "Режим презентации" end diff --git a/src/i18n/spanish.jl b/src/i18n/spanish.jl index 4e03adb..8723178 100644 --- a/src/i18n/spanish.jl +++ b/src/i18n/spanish.jl @@ -12,59 +12,181 @@ SpanishES = SpanishFormal # computational_thinking.jl PlutoTeachingTools.hint_str(lang::Lang) where {Lang<:Spanish} = "Pista" PlutoTeachingTools.tip_str(lang::Lang) where {Lang<:Spanish} = "Consejo" -PlutoTeachingTools.protip_invite_str(lang::Lang) where {Lang<:SpanishColloquial} = "¿Quieres aprender más?" -PlutoTeachingTools.protip_invite_str(lang::Lang) where {Lang<:SpanishFormal} = "¿Quiere aprender más?" +function PlutoTeachingTools.protip_invite_str(lang::Lang) where {Lang<:SpanishColloquial} + return "¿Quieres aprender más?" +end +function PlutoTeachingTools.protip_invite_str(lang::Lang) where {Lang<:SpanishFormal} + return "¿Quiere aprender más?" +end PlutoTeachingTools.protip_boxlabel_str(lang::Lang) where {Lang<:Spanish} = "Pinta Avanzada" -PlutoTeachingTools.answer_invite_str(lang::Lang) where {Lang<:SpanishColloquial} = "¿Quieres ver la respuesta?" -PlutoTeachingTools.answer_invite_str(lang::Lang) where {Lang<:SpanishFormal} = "¿Quiere ver la respuesta?" +function PlutoTeachingTools.answer_invite_str(lang::Lang) where {Lang<:SpanishColloquial} + return "¿Quieres ver la respuesta?" +end +function PlutoTeachingTools.answer_invite_str(lang::Lang) where {Lang<:SpanishFormal} + return "¿Quiere ver la respuesta?" +end PlutoTeachingTools.answer_boxlabel_str(lang::Lang) where {Lang<:Spanish} = "Respuesta" PlutoTeachingTools.almost_str(lang::Lang) where {Lang<:Spanish} = "¡Casi!" PlutoTeachingTools.warning_box_str(lang::Lang) where {Lang<:Spanish} = "Aviso:" PlutoTeachingTools.question_box_str(lang::Lang) where {Lang<:Spanish} = "Pregunta:" PlutoTeachingTools.danger_str(lang::Lang) where {Lang<:Spanish} = "¡Cuidado!" -PlutoTeachingTools.keyconcept_str(lang::Lang) where {Lang <: Spanish} = "🎯 Concepto clave" +PlutoTeachingTools.keyconcept_str(lang::Lang) where {Lang<:Spanish} = "🎯 Concepto clave" PlutoTeachingTools.still_missing_str(lang::Lang) where {Lang<:Spanish} = "Falta Respuesta" -PlutoTeachingTools.still_missing_text_str(lang::Lang) where {Lang<:SpanishColloquial} = md"Cambia `missing` con tu respuesta." -PlutoTeachingTools.still_missing_text_str(lang::Lang) where {Lang<:SpanishFormal} = md"Cambie `missing` con su respuesta." +function PlutoTeachingTools.still_missing_text_str( + lang::Lang +) where {Lang<:SpanishColloquial} + md"Cambia `missing` con tu respuesta." +end +function PlutoTeachingTools.still_missing_text_str(lang::Lang) where {Lang<:SpanishFormal} + md"Cambie `missing` con su respuesta." +end PlutoTeachingTools.still_nothing_str(lang::Lang) where {Lang<:Spanish} = "¡Ahí Vamos!" -PlutoTeachingTools.still_nothing_text_str(lang::Lang) where {Lang<:SpanishColloquial} = md"Cambia `nothing` con tu respuesta." -PlutoTeachingTools.still_nothing_text_str(lang::Lang) where {Lang<:SpanishFormal} = md"Cambie `nothing` con su respuesta." +function PlutoTeachingTools.still_nothing_text_str( + lang::Lang +) where {Lang<:SpanishColloquial} + md"Cambia `nothing` con tu respuesta." +end +function PlutoTeachingTools.still_nothing_text_str(lang::Lang) where {Lang<:SpanishFormal} + md"Cambie `nothing` con su respuesta." +end PlutoTeachingTools.wrong_type_str(lang::Lang) where {Lang<:Spanish} = "Error de Tipo" -PlutoTeachingTools.wrong_type_text_str(lang::Lang) where {Lang<:SpanishColloquial} = md"Comprueba el tipo de tu respuesta." -PlutoTeachingTools.wrong_type_text_str(lang::Lang) where {Lang<:SpanishFormal} = md"Compruebe el tipo de su respuesta." -PlutoTeachingTools.wrong_type_text_str(lang::Lang, var, type) where {Lang<:Spanish} = md"El tipo de $var debería de ser $type" +function PlutoTeachingTools.wrong_type_text_str(lang::Lang) where {Lang<:SpanishColloquial} + md"Comprueba el tipo de tu respuesta." +end +function PlutoTeachingTools.wrong_type_text_str(lang::Lang) where {Lang<:SpanishFormal} + md"Compruebe el tipo de su respuesta." +end +function PlutoTeachingTools.wrong_type_text_str(lang::Lang, var, type) where {Lang<:Spanish} + md"El tipo de $var debería de ser $type" +end PlutoTeachingTools.func_not_defined_str(lang::Lang) where {Lang<:Spanish} = "¡Ups!" -PlutoTeachingTools.func_not_defined_text_str(func_name, lang::Lang) where {Lang<:SpanishColloquial} = md"Debes definir una función llamada **$(Markdown.Code(string(func_name)))**" -PlutoTeachingTools.func_not_defined_text_str(func_name, lang::Lang) where {Lang<:SpanishFormal} = md"Debe definir una función llamada **$(Markdown.Code(string(func_name)))**" +function PlutoTeachingTools.func_not_defined_text_str( + func_name, lang::Lang +) where {Lang<:SpanishColloquial} + md"Debes definir una función llamada **$(Markdown.Code(string(func_name)))**" +end +function PlutoTeachingTools.func_not_defined_text_str( + func_name, lang::Lang +) where {Lang<:SpanishFormal} + md"Debe definir una función llamada **$(Markdown.Code(string(func_name)))**" +end PlutoTeachingTools.var_not_defined_str(lang::Lang) where {Lang<:Spanish} = "¡Ups!" -PlutoTeachingTools.var_not_defined_text_str(variable_name, lang::Lang) where {Lang<:SpanishColloquial} = md"Debes definir una variable llamada **$(Markdown.Code(string(variable_name)))**" -PlutoTeachingTools.var_not_defined_text_str(variable_name, lang::Lang) where {Lang<:SpanishFormal} = md"Debe definir una variable llamada **$(Markdown.Code(string(variable_name)))**" -PlutoTeachingTools.keep_working_str(lang::Lang) where {Lang<:SpanishColloquial} = "¡Sigue trabajando en ello!" -PlutoTeachingTools.keep_working_str(lang::Lang) where {Lang<:SpanishFormal} = "¡Siga trabajando en ello!" -PlutoTeachingTools.keep_working_text_str(lang::Lang) where {Lang<:Spanish} = md"La respuesta no es del todo correcta." -PlutoTeachingTools.keep_working_update_str(var, lang::Lang) where {Lang<:SpanishColloquial} = md"Asegúrate de actualizar la celda que define $var." -PlutoTeachingTools.keep_working_update_str(var, lang::Lang) where {Lang<:SpanishFormal} = md"Asegúrese de actualizar la celda que define $var." -PlutoTeachingTools.yays(lang::Lang) where {Lang<:SpanishColloquial} = [md"¡Genial!", md"Perfecto ❤", md"¡Genial! 🎉", md"¡Bien hecho!", md"¡Sigue así!", md"¡Buen trabajo!", md"¡Asombroso!", md"¡Tienes la respuesta correcta!", md"Avancemos a lo siguiente."] -PlutoTeachingTools.yays(lang::Lang) where {Lang<:SpanishFormal} = [md"¡Genial!", md"Perfecto ❤", md"¡Genial! 🎉", md"¡Bien hecho!", md"¡Siga así!", md"¡Buen trabajo!", md"¡Asombroso!", md"¡Tiene la respuesta correcta!", md"Avancemos a lo siguiente."] +function PlutoTeachingTools.var_not_defined_text_str( + variable_name, lang::Lang +) where {Lang<:SpanishColloquial} + md"Debes definir una variable llamada **$(Markdown.Code(string(variable_name)))**" +end +function PlutoTeachingTools.var_not_defined_text_str( + variable_name, lang::Lang +) where {Lang<:SpanishFormal} + md"Debe definir una variable llamada **$(Markdown.Code(string(variable_name)))**" +end +function PlutoTeachingTools.keep_working_str(lang::Lang) where {Lang<:SpanishColloquial} + return "¡Sigue trabajando en ello!" +end +function PlutoTeachingTools.keep_working_str(lang::Lang) where {Lang<:SpanishFormal} + return "¡Siga trabajando en ello!" +end +function PlutoTeachingTools.keep_working_text_str(lang::Lang) where {Lang<:Spanish} + md"La respuesta no es del todo correcta." +end +function PlutoTeachingTools.keep_working_update_str( + var, lang::Lang +) where {Lang<:SpanishColloquial} + md"Asegúrate de actualizar la celda que define $var." +end +function PlutoTeachingTools.keep_working_update_str( + var, lang::Lang +) where {Lang<:SpanishFormal} + md"Asegúrese de actualizar la celda que define $var." +end +function PlutoTeachingTools.yays(lang::Lang) where {Lang<:SpanishColloquial} + return [ + md"¡Genial!", + md"Perfecto ❤", + md"¡Genial! 🎉", + md"¡Bien hecho!", + md"¡Sigue así!", + md"¡Buen trabajo!", + md"¡Asombroso!", + md"¡Tienes la respuesta correcta!", + md"Avancemos a lo siguiente.", + ] +end +function PlutoTeachingTools.yays(lang::Lang) where {Lang<:SpanishFormal} + return [ + md"¡Genial!", + md"Perfecto ❤", + md"¡Genial! 🎉", + md"¡Bien hecho!", + md"¡Siga así!", + md"¡Buen trabajo!", + md"¡Asombroso!", + md"¡Tiene la respuesta correcta!", + md"Avancemos a lo siguiente.", + ] +end PlutoTeachingTools.correct_str(lang::Lang) where {Lang<:SpanishColloquial} = "¡Lo tienes!" PlutoTeachingTools.correct_str(lang::Lang) where {Lang<:SpanishFormal} = "¡Lo tiene!" PlutoTeachingTools.todo_str(lang::Lang) where {Lang<:Spanish} = "PENDIENTE" -PlutoTeachingTools.check_type_isa_missing_text_str(sym, lang::Lang) where {Lang<:Spanish} = md"La variable $sym sigue estando `missing`." -PlutoTeachingTools.check_type_isa_wrong_type_text_str(sym, lang::Lang) where {Lang<:Spanish} = "El tipo de $sym no es correcto. Debería de ser <: " -PlutoTeachingTools.check_type_isa_wrong_type_one_of_text_str(lang::Lang) where {Lang<:Spanish} = "uno de" -PlutoTeachingTools.check_type_isa_wrong_type_or_text_str(lang::Lang) where {Lang<:Spanish} = "o" -PlutoTeachingTools.check_type_isa_not_missing_text_str(sym, lang::Lang) where {Lang<:Spanish} = md"$sym tiene el tipo correcto." -PlutoTeachingTools.check_type_isa_type_error_str(sym, lang::Lang) where {Lang<:Spanish} = "Error de Tipo" +function PlutoTeachingTools.check_type_isa_missing_text_str( + sym, lang::Lang +) where {Lang<:Spanish} + md"La variable $sym sigue estando `missing`." +end +function PlutoTeachingTools.check_type_isa_wrong_type_text_str( + sym, lang::Lang +) where {Lang<:Spanish} + return "El tipo de $sym no es correcto. Debería de ser <: " +end +function PlutoTeachingTools.check_type_isa_wrong_type_one_of_text_str( + lang::Lang +) where {Lang<:Spanish} + return "uno de" +end +function PlutoTeachingTools.check_type_isa_wrong_type_or_text_str( + lang::Lang +) where {Lang<:Spanish} + return "o" +end +function PlutoTeachingTools.check_type_isa_not_missing_text_str( + sym, lang::Lang +) where {Lang<:Spanish} + md"$sym tiene el tipo correcto." +end +function PlutoTeachingTools.check_type_isa_type_error_str( + sym, lang::Lang +) where {Lang<:Spanish} + return "Error de Tipo" +end -PlutoTeachingTools.check_type_eq_missing_text_str(sym, lang::Lang) where {Lang<:Spanish} = md"La variable $sym aún es `missing`." -PlutoTeachingTools.check_type_eq_wrong_type_single_text_str(sym, type, lang::Lang) where {Lang<:Spanish} = "El tipo de $sym debería de ser $type." -PlutoTeachingTools.check_type_eq_wrong_type_multi_text_str(sym, lang::Lang) where {Lang<:Spanish} = "El tipo de $sym debería de ser uno de " -PlutoTeachingTools.check_type_eq_type_error_str(lang::Lang) where {Lang<:Spanish} = "Error de Tipo" -PlutoTeachingTools.check_type_eq_correct_str(sym, lang::Lang) where {Lang<:Spanish} = md"$sym tiene el tipo correcto." +function PlutoTeachingTools.check_type_eq_missing_text_str( + sym, lang::Lang +) where {Lang<:Spanish} + md"La variable $sym aún es `missing`." +end +function PlutoTeachingTools.check_type_eq_wrong_type_single_text_str( + sym, type, lang::Lang +) where {Lang<:Spanish} + return "El tipo de $sym debería de ser $type." +end +function PlutoTeachingTools.check_type_eq_wrong_type_multi_text_str( + sym, lang::Lang +) where {Lang<:Spanish} + return "El tipo de $sym debería de ser uno de " +end +function PlutoTeachingTools.check_type_eq_type_error_str(lang::Lang) where {Lang<:Spanish} + return "Error de Tipo" +end +function PlutoTeachingTools.check_type_eq_correct_str(sym, lang::Lang) where {Lang<:Spanish} + md"$sym tiene el tipo correcto." +end # other.jl -PlutoTeachingTools.full_width_mode_str(lang::Lang) where {Lang<:Spanish} = "Modo Pantalla Completa" +function PlutoTeachingTools.full_width_mode_str(lang::Lang) where {Lang<:Spanish} + return "Modo Pantalla Completa" +end # present.jl PlutoTeachingTools.present_str(lang::Lang) where {Lang<:Spanish} = "presentación" diff --git a/src/latex.jl b/src/latex.jl index 7aa8639..142914f 100644 --- a/src/latex.jl +++ b/src/latex.jl @@ -4,8 +4,9 @@ using Latexify using LaTeXStrings export latexify_md, wrap_tex - -latexify_md(args...; kwargs...) = Markdown.LaTeX(repr(MIME"text/latex"(), latexify(args...; kwargs...))) +function latexify_md(args...; kwargs...) + return Markdown.LaTeX(repr(MIME"text/latex"(), latexify(args...; kwargs...))) +end wrap_tex(x) = Markdown.LaTeX(repr(MIME"text/latex"(), x)) @@ -14,16 +15,15 @@ Issue also includes a suggestion to use begin using Latexify using LaTeXStrings - + Markdown.html(io::IO, ls::LaTeXString) = Markdown.html(io, Markdown.LaTeX( repr(MIME"text/latex"(), ls) )) - + Markdown.htmlinline(io::IO, ls::LaTeXString) = Markdown.htmlinline(io, Markdown.LaTeX( repr(MIME"text/latex"(), ls) )) end =# - diff --git a/src/other.jl b/src/other.jl index af5311f..ed7c53f 100644 --- a/src/other.jl +++ b/src/other.jl @@ -1,44 +1,45 @@ export WidthOverDocs """ Provides checkbox to toggle full width versus narrow with column for LiveDocs """ -function WidthOverDocs(enabled::Bool=false, wide::Bool=false, lang::AbstractLanguage = default_language[]) # From PlutoThemes.jl - checked = wide ? "checked" : "" - init = wide ? "toggle_width(document.getElementById('width-over-livedocs'))" : "" - return HTML(""" - - - - - -""") +function WidthOverDocs( + enabled::Bool=false, wide::Bool=false, lang::AbstractLanguage=default_language[] +) # From PlutoThemes.jl + checked = wide ? "checked" : "" + init = wide ? "toggle_width(document.getElementById('width-over-livedocs'))" : "" + return HTML(""" + + + + + + """) end - """ Display a full-screen confetti animation! The confetti will disappear automatically, and it will be fired every time the cell is re-run. @@ -84,15 +85,14 @@ end ``` """ function confetti() - HTML(""" - - """) + return HTML(""" + + """) end export confetti - diff --git a/src/present.jl b/src/present.jl index d47fe0c..7e627b2 100644 --- a/src/present.jl +++ b/src/present.jl @@ -8,7 +8,7 @@ export TwoColumn, ThreeColumn export TwoColumnWideLeft, TwoColumnWideRight export ChooseDisplayMode # combines present_button and WidthOverDocs -function present_button(lang::AbstractLanguage = default_language[]) +function present_button(lang::AbstractLanguage=default_language[]) txt = present_str(lang) htl"" end @@ -19,12 +19,13 @@ struct Foldable{C} end function Base.show(io, mime::MIME"text/html", fld::Foldable) - write(io,"
$(fld.title)

") + write(io, "

$(fld.title)

") show(io, mime, fld.content) - write(io,"

") + write(io, "

") + return nothing end -struct TwoColumn{L, R} +struct TwoColumn{L,R} left::L right::R end @@ -36,9 +37,10 @@ function Base.show(io, mime::MIME"text/html", tc::TwoColumn) write(io, """
""") show(io, mime, tc.right) write(io, """
""") + return nothing end -struct TwoColumnWideLeft{L, R} +struct TwoColumnWideLeft{L,R} left::L right::R end @@ -50,9 +52,10 @@ function Base.show(io, mime::MIME"text/html", tc::TwoColumnWideLeft) write(io, """
""") show(io, mime, tc.right) write(io, """
""") + return nothing end -struct TwoColumnWideRight{L, R} +struct TwoColumnWideRight{L,R} left::L right::R end @@ -63,10 +66,11 @@ function Base.show(io, mime::MIME"text/html", tc::TwoColumnWideRight) write(io, """
""") write(io, """
""") show(io, mime, tc.right) - write(io, """
""") + qwrite(io, """""") + return nothing end -struct ThreeColumn{L, C, R} +struct ThreeColumn{L,C,R} left::L center::C right::R @@ -82,14 +86,17 @@ function Base.show(io, mime::MIME"text/html", tc::ThreeColumn) write(io, """
""") show(io, mime, tc.right) write(io, """
""") + return nothing end """ Provides checkbox to toggle full width and present mode. """ -function ChooseDisplayMode(;wide::Bool=false, present::Bool = false, lang::AbstractLanguage = default_language[]) # Adapted from PlutoThemes.jl - checked = wide ? "checked" : "" - checked_present_mode = present ? "checked" : "" - init = wide ? "toggle_width(document.getElementById('width-over-livedocs'))" : "" - return HTML(""" +function ChooseDisplayMode(; + wide::Bool=false, present::Bool=false, lang::AbstractLanguage=default_language[] +) # Adapted from PlutoThemes.jl + checked = wide ? "checked" : "" + checked_present_mode = present ? "checked" : "" + init = wide ? "toggle_width(document.getElementById('width-over-livedocs'))" : "" + return HTML(""" 0 - return LocalResource(path, html_attributes... ) - elseif cache - mkpath(dirname(path)) - Downloads.download(url, path) - LocalResource(path, html_attributes... ) - else - Resource(url, html_attributes... ) - end -end +function RobustLocalResource( + url::AbstractString, path::AbstractString, html_attributes::Pair...; cache::Bool=true +) + if !(contains(url, r"^http") || contains(url, r"^ftp")) && + (contains(path, r"^http") || contains(path, r"^ftp")) + @warn "It looks like call to RobustLocalResource has incorrect order of url and path." + url, path = path, url + end + if isfile(path) && filesize(path) > 0 + return LocalResource(path, html_attributes...) + elseif cache + mkpath(dirname(path)) + Downloads.download(url, path) + LocalResource(path, html_attributes...) + else + Resource(url, html_attributes...) + end +end diff --git a/test/Project.toml b/test/Project.toml new file mode 100644 index 0000000..7c8e252 --- /dev/null +++ b/test/Project.toml @@ -0,0 +1,4 @@ +[deps] +JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899" +Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/runtests.jl b/test/runtests.jl index 4f7419d..6260a22 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,53 +1,56 @@ using PlutoTeachingTools using Test -using Markdown +using JuliaFormatter -@testset "PlutoTeachingTools.jl" begin - # Write your tests here. +using Markdown - @testset "Standard String arguments" begin - @test_nowarn hint("Test hint") - @test_nowarn almost("Testing almost") - @test_nowarn still_missing("Variable xxx is missing.") - @test_nowarn keep_working("Maybe the hint will help.") - @test_nowarn keyconcept("Julia", "Julia is an amazing programming language.") - end; - @testset "Markdown arguments" begin - @test_nowarn hint(md"Test hint") - @test_nowarn almost(md"Testing almost") - @test_nowarn still_missing(md"Variable xxx is missing.") - @test_nowarn keep_working(md"Maybe the hint will help.") - @test_nowarn keyconcept("Julia", md"Julia is an amazing programming language.") - end; +@testset verbose = true "PlutoTeachingTools.jl" begin + @testset verbose = true "Linting" begin + @testset "Code formatting" begin + @test JuliaFormatter.format(PlutoTeachingTools; verbose=false, overwrite=false) + end + end + + @testset "Admonitions" begin + @testset "Standard String arguments" begin + @test_nowarn hint("Test hint") + @test_nowarn almost("Testing almost") + @test_nowarn still_missing("Variable xxx is missing.") + @test_nowarn keep_working("Maybe the hint will help.") + @test_nowarn keyconcept("Julia", "Julia is an amazing programming language.") + end + @testset "Markdown arguments" begin + @test_nowarn hint(md"Test hint") + @test_nowarn almost(md"Testing almost") + @test_nowarn still_missing(md"Variable xxx is missing.") + @test_nowarn keep_working(md"Maybe the hint will help.") + @test_nowarn keyconcept("Julia", md"Julia is an amazing programming language.") + end + @test_nowarn (x = 5; var_not_defined(x)) + @test_nowarn (x = 5; not_defined(x)) + @test_nowarn (f(x) = x; func_not_defined(f)) + end @testset "aside" begin - @test_nowarn aside("testing aside") - @test_nowarn aside("testing aside with offset", v_offset=50) - @test_nowarn aside(md"testing in markdown") - @test_nowarn aside(tip(md"Good tip here")) - @test_nowarn aside(md""" -Testing -Multi-line -""") - - - end; - - @test_nowarn (x = 5; var_not_defined(x) ) - @test_nowarn (x = 5; not_defined(x) ) - @test_nowarn (f(x) = x; func_not_defined(f) ) + @test_nowarn aside("testing aside") + @test_nowarn aside("testing aside with offset", v_offset=50) + @test_nowarn aside(md"testing in markdown") + @test_nowarn aside(tip(md"Good tip here")) + @test_nowarn aside(md""" + Testing + Multi-line + """) + end @testset "Useful strings" begin - @test_nowarn TODO() - end; + @test_nowarn TODO() + end @testset "Changing width" begin - @test_nowarn WidthOverDocs() - end; + @test_nowarn WidthOverDocs() + end @testset "Ingredients" begin - @test typeof(@ingredients("empty_module.jl")) == Module - end; - + @test typeof(@ingredients("empty_module.jl")) == Module + end end -