Packages

A comprehensive platform-agnostic internationalization library for Gleam with multi-language date/time formatting, pluralization rules, and locale-aware number formatting

Current section

Files

Jump to
g18n src g18n@internal@format.erl
Raw

src/g18n@internal@format.erl

-module(g18n@internal@format).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/g18n/internal/format.gleam").
-export([format_string/2]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(false).
-file("src/g18n/internal/format.gleam", 20).
?DOC(false).
-spec format_string(binary(), gleam@dict:dict(binary(), binary())) -> binary().
format_string(Template, Params) ->
gleam@dict:fold(
Params,
Template,
fun(Acc, Key, Value) ->
gleam@string:replace(
Acc,
<<<<"{"/utf8, Key/binary>>/binary, "}"/utf8>>,
Value
)
end
).