Skip to content

Commit

Permalink
Fix __KEY__ order, fix lint nil value, remove logger warning on abili…
Browse files Browse the repository at this point in the history
…ties
  • Loading branch information
simonprev committed Nov 3, 2023
1 parent 802d3c1 commit ca99b09
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 26 deletions.
12 changes: 1 addition & 11 deletions lib/accent/auth/role_abilities.ex
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,5 @@ defmodule Accent.RoleAbilities do
end

# Fallback if no permission has been found for the user on the project
def can?(nil, _action, _), do: false

def can?(role, action, nil) do
Logger.warning("Unauthorized action: #{action} for #{role}")
false
end

def can?(role, action, target) do
Logger.warning("Unauthorized action: #{action} for #{role} on #{inspect(target)}")
false
end
def can?(_role, _action, _), do: false
end
2 changes: 1 addition & 1 deletion lib/accent/translations/translations_renderer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule Accent.TranslationsRenderer do
end

defp translations_to_entries(translations, master_translations, value_map) do
master_translations = Enum.group_by(master_translations || [], & &1.key)
master_translations = Enum.group_by(List.wrap(master_translations), & &1.key)

Enum.map(translations, fn translation ->
master_translation = Map.get(master_translations, translation.key)
Expand Down
2 changes: 1 addition & 1 deletion lib/langue/utils/nested_parser_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule Langue.Utils.NestedParserHelper do
if MapSet.member?(acc.keys, key) do
acc
else
key_entries = grouped_entries[key]
key_entries = Enum.sort_by(grouped_entries[key], &String.ends_with?(&1.key, "_"), :desc)

acc
|> Map.put(:results, [{key, key_entries} | acc.results])
Expand Down
2 changes: 1 addition & 1 deletion lib/lint/checks/double_spaces.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Accent.Lint.Checks.DoubleSpace do
def enabled?, do: not Accent.Lint.Checks.Spelling.enabled?()

@impl true
def applicable(_), do: true
def applicable(entry), do: is_binary(entry.value)

@impl true
def check(entry) do
Expand Down
2 changes: 1 addition & 1 deletion lib/lint/checks/leading_spaces.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Accent.Lint.Checks.LeadingSpaces do
def enabled?, do: true

@impl true
def applicable(entry), do: entry.value not in ["", " "]
def applicable(entry), do: entry.value not in [nil, "", " "]

@impl true
def check(entry) do
Expand Down
2 changes: 1 addition & 1 deletion lib/lint/checks/placeholder_count.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Accent.Lint.Checks.PlaceholderCount do
def enabled?, do: true

@impl true
def applicable(entry), do: not entry.is_master and is_binary(entry.master_value)
def applicable(entry), do: is_binary(entry.value) and not entry.is_master and is_binary(entry.master_value)

@impl true
def check(entry) do
Expand Down
1 change: 1 addition & 0 deletions lib/lint/checks/spelling.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule Accent.Lint.Checks.Spelling do
@impl true
def applicable(entry) do
LanguageTool.ready?() and
is_binary(entry.value) and
not String.match?(entry.value, ~r/MMM|YYY|HH|AA/i) and
not String.starts_with?(entry.value, "{") and
((!entry.is_master and entry.value !== entry.master_value) or entry.is_master) and
Expand Down
2 changes: 1 addition & 1 deletion lib/lint/checks/three_dots_ellipsis.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Accent.Lint.Checks.ThreeDotsEllipsis do
def enabled?, do: true

@impl true
def applicable(_), do: true
def applicable(entry), do: is_binary(entry.value)

@impl true
def check(entry) do
Expand Down
2 changes: 1 addition & 1 deletion lib/lint/checks/trailing_space.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Accent.Lint.Checks.TrailingSpaces do
def enabled?, do: true

@impl true
def applicable(entry), do: entry.value not in ["", " "]
def applicable(entry), do: entry.value not in ["", " ", nil]

@impl true
def check(entry) do
Expand Down
2 changes: 1 addition & 1 deletion lib/lint/checks/url_count.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Accent.Lint.Checks.URLCount do
def enabled?, do: true

@impl true
def applicable(entry), do: not entry.is_master and is_binary(entry.master_value)
def applicable(entry), do: is_binary(entry.value) and not entry.is_master and is_binary(entry.master_value)

@impl true
def check(entry) do
Expand Down
54 changes: 54 additions & 0 deletions test/langue/gettext/exceptions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule LangueTest.Formatter.Gettext.Exception do
@moduledoc false
use ExUnit.Case, async: true

alias Langue.Entry
alias Langue.Formatter.Gettext
alias LangueTest.Formatter.Gettext.Expectation.EmptyComment

Expand All @@ -12,4 +13,57 @@ defmodule LangueTest.Formatter.Gettext.Exception do

assert expected_parse == result_parse
end

test "plurialization export sorting" do
entries = [
%Entry{
index: 1,
key: "should be at least n character(s).__KEY__0",
value: "should be at least 0 characters",
plural: true,
value_type: "string"
},
%Entry{
index: 2,
key: "should be at least n character(s).__KEY__1",
value: "should be at least %{count} character(s)",
plural: true,
value_type: "string",
placeholders: ~w(%{count})
},
%Entry{
index: 3,
key: "should be at least n character(s).__KEY___",
value: "should be at least %{count} character(s)",
plural: true,
locked: true,
value_type: "plural",
placeholders: ~w(%{count})
}
]

result =
Gettext.serialize(%Langue.Formatter.ParserResult{
entries: entries,
language: %{slug: "foo", plural_forms: "none"},
document: %{top_of_the_file_comment: "", header: header()}
})

assert result.render === """
msgid ""
msgstr ""
"Language: foo"
msgid "should be at least n character(s)"
msgid_plural "should be at least %{count} character(s)"
msgstr[0] "should be at least 0 characters"
msgstr[1] "should be at least %{count} character(s)"
"""
end

def header do
String.trim_trailing(~S"""
"Language: fr"
""")
end
end
4 changes: 4 additions & 0 deletions vendor/language_tool/lib/language_tool/annotated_text.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ defmodule LanguageTool.AnnotatedText do
@moduledoc false
def build(input, regex) do
matches = if regex, do: Regex.scan(regex, input, return: :index), else: []
# Ignore HTML
matches = matches ++ Regex.scan(~r/<[^>]*>/, input, return: :index)
# Ignore % and $ often used as placeholders
matches = matches ++ Regex.scan(~r/[%$][\w\d]+/, input, return: :index)
matches = Enum.sort_by(matches, fn [{match_index, _}] -> match_index end)

split_tokens(input, matches, 0, [])
end

Expand Down
1 change: 0 additions & 1 deletion webapp/app/pods/components/projects-filters/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,5 @@ div.filters {
@media (max-width: 640px) {
div.filters {
padding: 0 10px;
margin-bottom: 20px;
}
}
11 changes: 5 additions & 6 deletions webapp/app/pods/components/recent-projects-list/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
display: flex;
flex-wrap: wrap;
position: relative;
gap: 4px 10px;
}

.item-link {
display: block;
padding: 4px 10px 5px;
margin-right: 12px;
background: var(--background-light);
border-radius: var(--border-radius);
text-decoration: none;
Expand All @@ -46,11 +46,10 @@
.projects {
align-items: flex-start;
flex-direction: column;
padding: 10px 15px;
margin-bottom: 0;
padding: 0;
margin-bottom: 14px;
}

.item-link {
margin-bottom: 10px;
.projects-title {
margin-bottom: 4px;
}
}

0 comments on commit ca99b09

Please sign in to comment.