Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ CONFIG = "_config.yml"
task default: [:build]

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

desc "Build the Jekyll site"
task :build do
Expand Down Expand Up @@ -129,3 +129,11 @@ Rake::TestTask.new(:"test-news-plugin") do |t|
t.test_files = FileList['test/test_plugin_news.rb']
t.verbose = true
end

require "rake/testtask"
Rake::TestTask.new(:"test-html-lang-plugin") do |t|
t.description = "Run tests for the HTML language plugin"
t.libs = ["test"]
t.test_files = FileList['test/test_plugin_html_lang.rb']
t.verbose = true
end
4 changes: 2 additions & 2 deletions _includes/language_selector.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<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">
<span class="text-stone-700 dark:text-stone-300">
{% if current_language %}
{{ current_language.native_name }}<span class="hidden sm:inline"> ({{ current_language.code }})</span>
{{ current_language.native_name }}<span class="hidden sm:inline"> (<span lang="und-Latn">{{ current_language.code }}</span>)</span>
{% else %}
English<span class="hidden sm:inline"> (en)</span>
<span lang="en">English<span class="hidden sm:inline"> (en)</span></span>
{% endif %}
</span>
<span class="icon-dropdown text-base" aria-hidden="true"></span>
Expand Down
39 changes: 39 additions & 0 deletions test/test_plugin_html_lang.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

require "helper"
require "liquid"
require_relative "../_plugins/html_lang"

describe Jekyll::HtmlLangFilter do
include Jekyll::HtmlLangFilter

describe "#to_html_lang" do
it "returns the same string if no underscore is present" do
_(to_html_lang("en")).must_equal "en"
_(to_html_lang("fr")).must_equal "fr"
end

it "converts Jekyll locale with underscore to BCP 47 format" do
_(to_html_lang("zh_cn")).must_equal "zh-CN"
_(to_html_lang("zh_tw")).must_equal "zh-TW"
_(to_html_lang("pt_br")).must_equal "pt-BR"
end

it "returns the input as is if it is not a string" do
_(to_html_lang(nil)).must_be_nil
_(to_html_lang(123)).must_equal 123
end
end

describe "integration with Liquid" do
it "is registered as a liquid filter" do
template = Liquid::Template.parse("{{ 'zh_cn' | to_html_lang }}")
_(template.render).must_equal "zh-CN"
end

it "works correctly in a liquid template for simple lang" do
template = Liquid::Template.parse("{{ 'en' | to_html_lang }}")
_(template.render).must_equal "en"
end
end
end
Loading