From e31be180c20a55fc0d22a3f6479f71952c4ad226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9ana=20=E6=B1=9F?= Date: Sat, 21 Jun 2025 00:48:13 +0200 Subject: [PATCH] vanadium: firefox search engine for each language and display language take 2 --- nix/configurations/vanadium/home/firefox.nix | 46 ++++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/nix/configurations/vanadium/home/firefox.nix b/nix/configurations/vanadium/home/firefox.nix index 69923a91..8e7ef553 100644 --- a/nix/configurations/vanadium/home/firefox.nix +++ b/nix/configurations/vanadium/home/firefox.nix @@ -5,10 +5,6 @@ ... }: let inherit (pkgs) nur; - - # reference: https://developers.google.com/custom-search/docs/xml_results?hl=zh-tw#advanced-search-query-parameters - mkLrFlag = languageRestrictions: - "&lr=" + lib.escapeURL (builtins.concatStringsSep "|" languageRestrictions); in { programs.firefox = { enable = true; @@ -17,23 +13,37 @@ in { RequestedLocales = ["fr" "en-US" "zh-TW"]; SearchEngines = { - Default = "Google EN"; + Default = "Google en@en"; Remove = ["Google"]; Add = let - langs = ["lang_fr" "lang_en" "lang_zh-TW"]; + lrValues = ["lang_fr" "lang_en" "lang_zh-TW"]; + hlValues = ["fr" "en" "zh-TW"]; in - # Google specialized for each language - map (lang: let - shortcode = lib.substring 0 2 (lib.removePrefix "lang_" lang); - in { - Name = "Google " + lib.toUpper shortcode; - Alias = "G" + shortcode; - IconURL = "https://google.com/favicon.ico"; - Description = "Your data yum yum (but ${shortcode})"; - SuggestURLTemplate = "https://suggestqueries.google.com/complete/search?q={searchTerms}" + mkLrFlag [lang]; - URLTemplate = "https://google.com/search?q={searchTerms}" + mkLrFlag [lang]; - }) - langs + # Google specialized for each language x display language + # reference: https://developers.google.com/custom-search/docs/xml_results?hl=zh-tw#advanced-search-query-parameters + lib.mapCartesianProduct ( + { + lr, + hl, + }: let + lr' = lib.substring 0 2 (lib.removePrefix "lang_" lr); + hl' = lib.substring 0 2 hl; + in { + Name = "Google ${lr'}@${hl'}"; + Alias = + if (lib.removePrefix "lang_" lr == hl) + then "G" + lr' + else "G" + lr' + hl'; + Description = "Your data yum yum (but ${lr'} in ${hl'})"; + IconURL = "https://google.com/favicon.ico"; + SuggestURLTemplate = "https://suggestqueries.google.com/complete/search?q={searchTerms}&lr=${lr}&hl=${hl}"; + URLTemplate = "https://google.com/search?q={searchTerms}&lr=${lr}&hl=${hl}"; + } + ) + { + lr = lrValues; + hl = hlValues; + } ++ [ { Name = "YouTube";