Skip to content

Commit 0f00cd1

Browse files
authored
Merge pull request #3744 from liberaldev/add-html-lang-test-and-more
Add html lang test and more
2 parents 9541964 + 6b632da commit 0f00cd1

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

Rakefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ CONFIG = "_config.yml"
1414
task default: [:build]
1515

1616
desc "Run tests (test-linter, lint, build)"
17-
task test: %i[test-news-plugin test-linter lint build]
17+
task test: %i[test-news-plugin test-html-lang-plugin test-linter lint build]
1818

1919
desc "Build the Jekyll site"
2020
task :build do
@@ -129,3 +129,11 @@ Rake::TestTask.new(:"test-news-plugin") do |t|
129129
t.test_files = FileList['test/test_plugin_news.rb']
130130
t.verbose = true
131131
end
132+
133+
require "rake/testtask"
134+
Rake::TestTask.new(:"test-html-lang-plugin") do |t|
135+
t.description = "Run tests for the HTML language plugin"
136+
t.libs = ["test"]
137+
t.test_files = FileList['test/test_plugin_html_lang.rb']
138+
t.verbose = true
139+
end

_includes/language_selector.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
<button class="flex items-center gap-1 px-3 py-1.5 text-sm border border-stone-300 dark:border-stone-600 rounded-md hover:bg-stone-100 dark:hover:bg-stone-800 transition-colors">
1818
<span class="text-stone-700 dark:text-stone-300">
1919
{% if current_language %}
20-
{{ current_language.native_name }}<span class="hidden sm:inline"> ({{ current_language.code }})</span>
20+
{{ current_language.native_name }}<span class="hidden sm:inline"> (<span lang="und-Latn">{{ current_language.code }}</span>)</span>
2121
{% else %}
22-
English<span class="hidden sm:inline"> (en)</span>
22+
<span lang="en">English<span class="hidden sm:inline"> (en)</span></span>
2323
{% endif %}
2424
</span>
2525
<span class="icon-dropdown text-base" aria-hidden="true"></span>

stylesheets/compiled.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,14 @@ body:is(.dark *){
19841984
color: rgb(250 250 249 / var(--tw-text-opacity, 1));
19851985
}
19861986

1987+
[lang]:lang(ja),[lang]:lang(ko),[lang]:lang(zh-CN),[lang]:lang(zh-TW) {
1988+
font-family: "Plus Jakarta Sans", var(--noto-sans-subset), -apple-system, BlinkMacSystemFont, sans-serif;
1989+
}
1990+
1991+
[lang]{
1992+
font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, sans-serif;
1993+
}
1994+
19871995
/* CJK fonts */
19881996

19891997
html:lang(ja),

stylesheets/tailwind.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
@apply dark:bg-stone-900 dark:text-stone-50;
2525
}
2626

27+
[lang] {
28+
@apply font-default;
29+
}
30+
2731
/* CJK fonts */
2832
html:lang(ja),
2933
body:lang(ja),

test/test_plugin_html_lang.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
require "helper"
4+
require "liquid"
5+
require_relative "../_plugins/html_lang"
6+
7+
describe Jekyll::HtmlLangFilter do
8+
include Jekyll::HtmlLangFilter
9+
10+
describe "#to_html_lang" do
11+
it "returns the same string if no underscore is present" do
12+
_(to_html_lang("en")).must_equal "en"
13+
_(to_html_lang("fr")).must_equal "fr"
14+
end
15+
16+
it "converts Jekyll locale with underscore to BCP 47 format" do
17+
_(to_html_lang("zh_cn")).must_equal "zh-CN"
18+
_(to_html_lang("zh_tw")).must_equal "zh-TW"
19+
_(to_html_lang("pt_br")).must_equal "pt-BR"
20+
end
21+
22+
it "returns the input as is if it is not a string" do
23+
_(to_html_lang(nil)).must_be_nil
24+
_(to_html_lang(123)).must_equal 123
25+
end
26+
end
27+
28+
describe "integration with Liquid" do
29+
it "is registered as a liquid filter" do
30+
template = Liquid::Template.parse("{{ 'zh_cn' | to_html_lang }}")
31+
_(template.render).must_equal "zh-CN"
32+
end
33+
34+
it "works correctly in a liquid template for simple lang" do
35+
template = Liquid::Template.parse("{{ 'en' | to_html_lang }}")
36+
_(template.render).must_equal "en"
37+
end
38+
end
39+
end

0 commit comments

Comments
 (0)