PageSourceSearch

https://www.avermedia.com/en/assets/cache/670e2706389113c6e046ccc69f1efc43.js

js avermedia.com collected 2026-09-24 10:05:19 UTC 3,383 bytes, 90 lines download raw bytes

1/**
2 * jQuery Validation Auto-Localization Plugin Extension
3 * 
4 * Automatically detects the browser or page language and loads the matching 
5 * localization messages from the 'localization/' directory.
6 *
7 * Requirements: 
8 * 1. jQuery (https://jquery.com/)
9 * 2. jQuery Validation Plugin (https://jqueryvalidation.org/)
10 *
11 * Load this script AFTER jquery.validate.js.
12 */
13(function($) {
14    if (!$.validator) {
15        console.error("jQuery Validation plugin not found. Please include jquery.validate.js.");
16        return;
17    }
18
19    if (typeof navigator === "undefined" || typeof document === "undefined") {
20        return;
21    }
22
23    // List of available locale files in the /localization directory
24    var supported = [
25        "ar", "az", "bg", "bn_BD", "ca", "cs", "da", "de", "el", "en", "es", "es_AR",
26        "es_PE", "et", "eu", "fa", "fi", "fr", "ge", "gl", "he", "hr", "hu",
27        "hy_AM", "id", "is", "it", "ja", "ka", "kk", "ko", "lt", "lv", "mk",
28        "my", "nl", "no", "pl", "pt_BR", "pt_PT", "ro", "ru", "sd", "si", "sk",
29        "sl", "sr", "sr_lat", "sv", "th", "tj", "tr", "uk", "ur", "vi", "zh", "zh_TW"
30    ];
31
32    // Detection: Prioritize <html> lang attribute, then navigator.language
33    var htmlLang = document.documentElement.getAttribute("lang");
34    var lang = (htmlLang || navigator.language || navigator.userLanguage || "en").replace("-", "_");
35
36    // Custom aliases for non-standard locale codes
37    var aliases = {
38        "jp": "ja",
39        "jp_JP": "ja",
40        "en_GB": "en",
41        "en_US": "en"
42    };
43
44    // Step 1: Resolve the target locale using aliases, exact match, or base language fallback
45    var target = "";
46    
47    // Check aliases first
48    if (aliases[lang]) {
49        target = aliases[lang];
50    } 
51    // Then check exact match in whitelist
52    else if (supported.indexOf(lang) !== -1) {
53        target = lang;
54    } 
55    // Finally fallback to the base language (e.g. "zh_HK" -> "zh")
56    else {
57        var base = lang.split("_")[0];
58        if (aliases[base]) {
59            target = aliases[base];
60        } else if (supported.indexOf(base) !== -1) {
61            target = base;
62        }
63    }
64
65    if (target) {
66        // Step 2: Determine localization base path. 
67        // Priority: $.validator.localizationPath > global validatorLocalePath > auto-detection
68        var dirPath = ($.validator && $.validator.localizationPath) || window.validatorLocalePath || "";
69
70        if (!dirPath) {
71            var scripts = document.getElementsByTagName("script");
72            for (var i = 0; i < scripts.length; i++) {
73                var src = scripts[i].getAttribute("src") || scripts[i].src;
74                // Detect path based on this script or the main plugin script
75                if (src && (src.indexOf("jquery.validate") !== -1 || src.indexOf("auto-localization") !== -1)) {
76                    var baseDir = src.substring(0, src.lastIndexOf("/") + 1);
77                    // Ensure it points to the localization subfolder
78                    dirPath = (baseDir.indexOf("localization") === -1) ? baseDir + "localization/" : baseDir;
79                    break;
80                }
81            }
82        }
83
84        // Step 3: Performance non-blocking load of the .min.js localization file
85        if (dirPath) {
86            $.getScript(dirPath + "messages_" + target + ".min.js");
87        }
88    }
89})(jQuery);
90

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.