]> git.openstreetmap.org Git - rails.git/blob - .erb_linters/custom_hard_coded_string.rb
Localisation updates from https://translatewiki.net.
[rails.git] / .erb_linters / custom_hard_coded_string.rb
1 # frozen_string_literal: true
2
3 require "better_html/tree/tag"
4 require "active_support/core_ext/string/inflections"
5
6 module ERBLint
7   module Linters
8     # A customised version of the HardCodedString linter, adding `·` as not needing translation
9     # Checks for hardcoded strings. Useful if you want to ensure a string can be translated using i18n.
10     class CustomHardCodedString < HardCodedString
11       include LinterRegistry
12
13       NO_TRANSLATION_NEEDED = Set.new([
14                                         "&nbsp;",
15                                         "&amp;",
16                                         "&lt;",
17                                         "&gt;",
18                                         "&quot;",
19                                         "&copy;",
20                                         "&reg;",
21                                         "&trade;",
22                                         "&hellip;",
23                                         "&mdash;",
24                                         "&bull;",
25                                         "&ldquo;",
26                                         "&rdquo;",
27                                         "&lsquo;",
28                                         "&rsquo;",
29                                         "&larr;",
30                                         "&rarr;",
31                                         "&darr;",
32                                         "&uarr;",
33                                         "&ensp;",
34                                         "&emsp;",
35                                         "&thinsp;",
36                                         "&times;",
37                                         "&laquo;",
38                                         "&raquo;",
39                                         "&middot;"
40                                       ])
41
42       private
43
44       def check_string?(str)
45         string = str.gsub(/\s*/, "")
46         string.length > 1 && !NO_TRANSLATION_NEEDED.include?(string)
47       end
48     end
49   end
50 end