Skip to content

Commit af336fc

Browse files
resolve mix docs issue + dependency updates (#44)
* add mix docs to git workflow to ensure they build * remove erroneous earmark dep * remove applications config * version bump and changelog updates * add 1.13 to test matrix * use actions cache@v4 * update deps * add readme status badges * cleanup mix file * docs and typo fixes * add dependabot config * update git ignore * update codeowners
1 parent 40b2f97 commit af336fc

14 files changed

+182
-115
lines changed

.formatter.exs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Used by "mix format"
12
[
23
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
34
]

.github/CODEOWNERS

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Tag Change.org on changes to repo
2+
* @change/co-elixir

.github/dependabot.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
3+
updates:
4+
- package-ecosystem: "mix"
5+
directory: "/"
6+
schedule:
7+
interval: "daily"
8+
open-pull-requests-limit: 5
9+
10+
- package-ecosystem: "docker"
11+
directory: "/"
12+
schedule:
13+
interval: "weekly"

.github/workflows/test.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
include:
1717
- elixir: '1.11'
1818
otp: '23'
19+
- elixir: '1.13'
20+
otp: '24'
1921
- elixir: '1.15'
2022
otp: '25'
2123

@@ -30,7 +32,7 @@ jobs:
3032
otp-version: ${{ matrix.otp }}
3133

3234
- name: Restore deps cache
33-
uses: actions/cache@v2
35+
uses: actions/cache@v4
3436
with:
3537
path: deps
3638
key: ${{ runner.os }}-mix-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }}
@@ -39,7 +41,7 @@ jobs:
3941
${{ runner.os }}-mix-${{ matrix.otp }}-${{ matrix.elixir }}
4042
4143
- name: Restore _build cache
42-
uses: actions/cache@v2
44+
uses: actions/cache@v4
4345
with:
4446
path: _build
4547
key: ${{ runner.os }}-build-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }}
@@ -64,3 +66,6 @@ jobs:
6466

6567
- name: Run unit tests
6668
run: mix test
69+
70+
- name: Build docs (validate build)
71+
run: mix docs

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ erl_crash.dump
1717
.sobelow
1818

1919
/doc
20+
21+
# Ignore tarball, built by "mix hex.build"
22+
linguist-*.tar

CHANGELOG.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
# Changelog
22

3-
## v0.4.0 (2024-01-31)
4-
* Add ci test and support Elixir 1.15 and OTP 25
5-
* Upgrade `ex_cldr` to version 2.37
3+
## v0.4.0 (2024-02-05)
64
* Now requires Elixir ~> 1.11
5+
* Add Elixir 1.15 and OTP 25 to ci test matrix
6+
* Upgrade `ex_cldr` to version 2.37
7+
* Add mix docs to ci workflow, to ensure docs build after changes
8+
* Add Elixir 1.13 OTP 24 to ci test matrix
9+
* Remove unused `earmark` dep
10+
* Remove unnecessary `applications:` config causing error with `mix docs`
11+
* Update dependencies + credo fixes
12+
* Update readme, add status badges
13+
* Updates docs and typo fixes
14+
+ Add dependabot and codeowner configs
715

816
## v0.3.2 (2021-08-11)
917
Wow, I held on to this release waaaaaay too long. Sorry about that. Also, a *huge thank you to @dolfinus for their contributes* (and nudges)!
@@ -40,7 +48,6 @@ Here's what changed:
4048
## v0.2.1 (2019-01-25)
4149
* [Add helper function](https://github.com/mertonium/linguist/commit/06807327e5095e54dd584ad5d65469e4358c92b4) for normalizing locales argument in MemorizedVocubalary.t/3. Locales will be made into the format "es-ES" or "es"
4250

43-
4451
## v0.2.0 (2018-10-22)
4552
* **LARGE SCALE REFACTOR** described in [this pull request](https://github.com/mertonium/linguist/pull/22)
4653

@@ -49,21 +56,19 @@ Here's what changed:
4956
* Bug Fixes
5057
* Fix bug causing interpolations at beginning of string to be missed
5158

52-
5359
## v0.1.0 (2014-07-06)
5460

5561
* Enhancements
5662
* Add `locale` macro for locale definitions
5763
* Support String filepath locale source for automated evaluation
58-
* Suppport arbitrary locale source to fetch keyword list of translations, ie function call, Code.eval_file, etc.
64+
* Support arbitrary locale source to fetch keyword list of translations, ie function call, Code.eval_file, etc.
5965
* Add `t!` lookups where `NoTranslationError` is raised if translation not found
6066

6167
* Backwards incompatible changes
6268
* Rename `Linguist.Compiler` to `Linguist.Vocabulary`
6369
* Locale definitions now required to use `locale/2` macro instead of `use` options
6470
* Update `t` lookups to return `{:ok, translation}` or `{:error, :no_translation}`
6571

66-
6772
## v0.0.1 (2014-06-28)
6873

6974
Initial release

README.md

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
11
# Linguist
2+
3+
[![Test](https://github.com/change/linguist/actions/workflows/test.yml/badge.svg)](https://github.com/change/linguist/actions/workflows/test.yml)
4+
[![Version on Hex.pm](https://img.shields.io/hexpm/v/linguist.svg)](https://hex.pm/packages/linguist)
5+
[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/linguist)
6+
[![Hex.pm downloads](https://img.shields.io/hexpm/dt/linguist.svg)](https://hex.pm/packages/linguist)
7+
[![License](https://img.shields.io/hexpm/l/linguist.svg)](https://github.com/change/linguist/blob/master/LICENSE)
8+
[![Latest commit](https://img.shields.io/github/last-commit/change/linguist.svg)](https://github.com/change/linguist/commits/master)
9+
![GitHub top language](https://img.shields.io/github/languages/top/change/linguist)
10+
211
> Linguist is a simple Elixir Internationalization library
312
13+
## Installation
14+
15+
Add `:linguist` to your `mix.exs` dependencies:
16+
17+
```elixir
18+
def deps do
19+
[
20+
{:linguist, "~> 0.4"}
21+
]
22+
end
23+
```
24+
25+
Update your dependencies:
26+
27+
```bash
28+
$ mix deps.get
29+
```
430

531
## Usage
632

733
```elixir
834
defmodule I18n do
935
use Linguist.Vocabulary
10-
36+
1137
locale "en", [
1238
flash: [
1339
notice: [
@@ -22,9 +48,8 @@ defmodule I18n do
2248
]
2349
]
2450
]
25-
26-
locale "fr", Path.join([__DIR__, "fr.exs"])
2751

52+
locale "fr", Path.join([__DIR__, "fr.exs"])
2853
end
2954

3055
# fr.exs

lib/linguist.ex

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
defmodule Linguist do
2+
@moduledoc false
23
defmodule NoTranslationError do
34
defexception [:message]
45

@@ -13,7 +14,7 @@ defmodule Linguist do
1314
@impl true
1415
def exception(value) do
1516
msg =
16-
"Invalid locale: expected a locale in the format 'es-ES' or 'es', but recieved: #{value}"
17+
"Invalid locale: expected a locale in the format 'es-ES' or 'es', but received: #{value}"
1718

1819
%LocaleError{message: msg}
1920
end

lib/linguist/cldr_backend.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule Linguist.Cldr do
22
@moduledoc """
3-
Backend Module for Cldr App configuration, required for ~> 2.0
3+
Backend Module for Cldr App configuration, required for ~> 2.0.
44
"""
55
use Cldr,
66
otp_app: :linguist,

lib/linguist/compiler.ex

+22-18
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
defmodule Linguist.Compiler do
2+
@moduledoc """
3+
Translation Compiler Module.
4+
"""
25
alias Linguist.Cldr.Number.Cardinal
36
alias Linguist.NoTranslationError
47

58
@doc ~S"""
6-
Compiles keyword list of transactions into function definitions AST
9+
Compiles keyword list of transactions into function definitions AST.
710
8-
Examples
11+
## Examples
912
10-
iex> Linguist.Compiler.compile(en: [
11-
hello: "Hello %{name}",
12-
alert: "Alert!"
13-
])
13+
iex> Linguist.Compiler.compile(en: [
14+
hello: "Hello %{name}",
15+
alert: "Alert!"
16+
])
1417
15-
quote do
16-
def t(locale, path, binding \\ [])
18+
quote do
19+
def t(locale, path, binding \\ [])
1720
18-
def t("en", "hello", bindings), do: "Hello " <> Keyword.fetch!(bindings, :name)
19-
def t("en", "alert", bindings), do: "Alert!"
21+
def t("en", "hello", bindings), do: "Hello " <> Keyword.fetch!(bindings, :name)
22+
def t("en", "alert", bindings), do: "Alert!"
2023
21-
def t(_locale, _path, _bindings), do: {:error, :no_translation}
22-
def t!(locale, path, bindings \\ []) do
23-
case t(locale, path, bindings) do
24-
{:ok, translation} -> translation
25-
{:error, :no_translation} ->
26-
raise %NoTranslationError{message: "#{locale}: #{path}"}
24+
def t(_locale, _path, _bindings), do: {:error, :no_translation}
25+
def t!(locale, path, bindings \\ []) do
26+
case t(locale, path, bindings) do
27+
{:ok, translation} -> translation
28+
{:error, :no_translation} ->
29+
raise %NoTranslationError{message: "#{locale}: #{path}"}
30+
end
31+
end
2732
end
28-
end
29-
end
3033
"""
3134

3235
@interpol_rgx ~r/
@@ -41,6 +44,7 @@ defmodule Linguist.Compiler do
4144
@escaped_interpol_rgx ~r/%%{/
4245
@simple_interpol "%{"
4346

47+
# credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity
4448
def compile(translations) do
4549
langs =
4650
translations

lib/linguist/memorized_vocabulary.ex

+27-24
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
defmodule Linguist.MemorizedVocabulary do
22
alias Linguist.Cldr.Number.Cardinal
3-
alias Linguist.Compiler
4-
alias Linguist.{LocaleError, NoTranslationError}
3+
alias Linguist.{Compiler, LocaleError, NoTranslationError}
54

65
defmodule TranslationDecodeError do
76
defexception [:message]
87
end
98

109
@moduledoc """
11-
Defines lookup functions for given translation locales, binding interopolation
10+
Defines lookup functions for given translation locales, binding interpolation.
1211
1312
Locales are defined with the `locale/2` function, accepting a locale name and
1413
a String path to evaluate for the translations list.
1514
16-
For example, given the following translations :
17-
18-
locale "en", [
19-
flash: [
20-
notice: [
21-
hello: "hello %{first} %{last}",
15+
For example, given the following translations:
16+
17+
locale "en", [
18+
flash: [
19+
notice: [
20+
hello: "hello %{first} %{last}",
21+
]
22+
],
23+
users: [
24+
title: "Users",
25+
]
2226
]
23-
],
24-
users: [
25-
title: "Users",
26-
]
27-
]
2827
29-
locale "fr", Path.join([__DIR__, "fr.exs"])
28+
locale "fr", Path.join([__DIR__, "fr.exs"])
29+
30+
This module will respond to these functions:
3031
31-
this module will respond to these functions :
32+
t("en", "flash.notice.hello", bindings \\ []), do: # ...
33+
t("en", "users.title", bindings \\ []), do: # ...
34+
t("fr", "flash.notice.hello", bindings \\ []), do: # ...
3235
33-
t("en", "flash.notice.hello", bindings \\ []), do: # ...
34-
t("en", "users.title", bindings \\ []), do: # ...
35-
t("fr", "flash.notice.hello", bindings \\ []), do: # ...
3636
"""
3737
def t(locale, path, bindings \\ [])
3838
def t(nil, _, _), do: raise(LocaleError, nil)
@@ -118,14 +118,15 @@ defmodule Linguist.MemorizedVocabulary do
118118
end
119119

120120
@doc """
121-
Embeds locales from provided source
121+
Embeds locales from provided source.
122122
123123
* name - The String name of the locale, ie "en", "fr"
124124
* source - The String file path to load YAML from that returns a structured list of translations
125125
126-
Examples
126+
## Examples
127+
128+
locale "es", Path.join([__DIR__, "es.yml"])
127129
128-
locale "es", Path.join([__DIR__, "es.yml"])
129130
"""
130131
def locale(name, source) do
131132
loaded_source = Linguist.MemorizedVocabulary._load_yaml_file(source)
@@ -134,8 +135,9 @@ defmodule Linguist.MemorizedVocabulary do
134135
end
135136

136137
@doc """
137-
Function used internally to load a yaml file. Please use
138-
the `locale` macro with a path to a yaml file - this function
138+
Function used internally to load a yaml file.
139+
140+
Please use the `locale` macro with a path to a yaml file - this function
139141
will not work as expected if called directly.
140142
"""
141143
def _load_yaml_file(source) do
@@ -161,6 +163,7 @@ defmodule Linguist.MemorizedVocabulary do
161163

162164
@doc """
163165
Recursive function used internally for loading yaml files.
166+
164167
Not intended for external use
165168
"""
166169
def _yaml_reducer({key, value}, acc) when is_binary(value) do

0 commit comments

Comments
 (0)