Packages

A lightweight Gleam library for formatting timestamps as human-readable relative time strings (e.g., '5 minutes ago', 'in 2 hours') with support for multiple locales.

Current section

8 Versions

Jump to

Compare versions

5 files changed
+152 additions
-4 deletions
  @@ -1,5 +1,5 @@
1 1 name = "timeago"
2 - version = "2.1.0"
2 + version = "2.2.0"
3 3
4 4 # Fill out these fields if you intend to generate HTML documentation or publish
5 5 # your project to the Hex package manager.
  @@ -1,6 +1,6 @@
1 1 {<<"name">>, <<"timeago">>}.
2 2 {<<"app">>, <<"timeago">>}.
3 - {<<"version">>, <<"2.1.0">>}.
3 + {<<"version">>, <<"2.2.0">>}.
4 4 {<<"description">>, <<"A lightweight Gleam library for formatting timestamps as human-readable relative time strings (e.g., '5 minutes ago', 'in 2 hours') with support for multiple locales."/utf8>>}.
5 5 {<<"licenses">>, [<<"Apache-2.0">>]}.
6 6 {<<"build_tools">>, [<<"gleam">>]}.
  @@ -1,5 +1,5 @@
1 1 {application, timeago, [
2 - {vsn, "2.1.0"},
2 + {vsn, "2.2.0"},
3 3 {applications, [gleam_stdlib,
4 4 gleam_time]},
5 5 {description, "A lightweight Gleam library for formatting timestamps as human-readable relative time strings (e.g., '5 minutes ago', 'in 2 hours') with support for multiple locales."},
  @@ -1,7 +1,7 @@
1 1 -module(timeago).
2 2 -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
3 3 -define(FILEPATH, "src/timeago.gleam").
4 - -export([with_now/2, with_locale/2, format/2, en_us/3, new/0, fr/3]).
4 + -export([with_now/2, with_locale/2, format/2, en_us/3, new/0, fr/3, pt_br/3]).
5 5 -export_type([time_ago/0, tense/0]).
6 6
7 7 -if(?OTP_RELEASE >= 27).
  @@ -405,3 +405,116 @@ fr(Tense, Unit, Amount) ->
405 405 _pipe@13 = <<"dans %d ans"/utf8>>,
406 406 replace_percent_d_with_int(_pipe@13, A@13)
407 407 end.
408 +
409 + -file("src/timeago.gleam", 249).
410 + ?DOC(" Translations for Brazilian Portuguese.\n").
411 + -spec pt_br(tense(), gleam@time@duration:unit(), integer()) -> binary().
412 + pt_br(Tense, Unit, Amount) ->
413 + case {Tense, Unit, Amount} of
414 + {_, nanosecond, _} ->
415 + <<"agora mesmo"/utf8>>;
416 +
417 + {_, microsecond, _} ->
418 + <<"agora mesmo"/utf8>>;
419 +
420 + {_, millisecond, _} ->
421 + <<"agora mesmo"/utf8>>;
422 +
423 + {past, second, 1} ->
424 + <<"1 segundo atrás"/utf8>>;
425 +
426 + {past, second, A} ->
427 + _pipe = <<"%d segundos atrás"/utf8>>,
428 + replace_percent_d_with_int(_pipe, A);
429 +
430 + {past, minute, 1} ->
431 + <<"1 minuto atrás"/utf8>>;
432 +
433 + {past, minute, A@1} ->
434 + _pipe@1 = <<"%d minutos atrás"/utf8>>,
435 + replace_percent_d_with_int(_pipe@1, A@1);
436 +
437 + {past, hour, 1} ->
438 + <<"1 hora atrás"/utf8>>;
439 +
440 + {past, hour, A@2} ->
441 + _pipe@2 = <<"%d horas atrás"/utf8>>,
442 + replace_percent_d_with_int(_pipe@2, A@2);
443 +
444 + {past, day, 1} ->
445 + <<"1 dia atrás"/utf8>>;
446 +
447 + {past, day, A@3} ->
448 + _pipe@3 = <<"%d dias atrás"/utf8>>,
449 + replace_percent_d_with_int(_pipe@3, A@3);
450 +
451 + {past, week, 1} ->
452 + <<"1 semana atrás"/utf8>>;
453 +
454 + {past, week, A@4} ->
455 + _pipe@4 = <<"%d semanas atrás"/utf8>>,
456 + replace_percent_d_with_int(_pipe@4, A@4);
457 +
458 + {past, month, 1} ->
459 + <<"1 mês atrás"/utf8>>;
460 +
461 + {past, month, A@5} ->
462 + _pipe@5 = <<"%d meses atrás"/utf8>>,
463 + replace_percent_d_with_int(_pipe@5, A@5);
464 +
465 + {past, year, 1} ->
466 + <<"1 ano atrás"/utf8>>;
467 +
468 + {past, year, A@6} ->
469 + _pipe@6 = <<"%d anos atrás"/utf8>>,
470 + replace_percent_d_with_int(_pipe@6, A@6);
471 +
472 + {future, second, 1} ->
473 + <<"daqui a 1 segundo"/utf8>>;
474 +
475 + {future, second, A@7} ->
476 + _pipe@7 = <<"daqui a %d segundos"/utf8>>,
477 + replace_percent_d_with_int(_pipe@7, A@7);
478 +
479 + {future, minute, 1} ->
480 + <<"daqui a 1 minuto"/utf8>>;
481 +
482 + {future, minute, A@8} ->
483 + _pipe@8 = <<"daqui a %d minutos"/utf8>>,
484 + replace_percent_d_with_int(_pipe@8, A@8);
485 +
486 + {future, hour, 1} ->
487 + <<"daqui a 1 hora"/utf8>>;
488 +
489 + {future, hour, A@9} ->
490 + _pipe@9 = <<"daqui a %d horas"/utf8>>,
491 + replace_percent_d_with_int(_pipe@9, A@9);
492 +
493 + {future, day, 1} ->
494 + <<"daqui a 1 dia"/utf8>>;
495 +
496 + {future, day, A@10} ->
497 + _pipe@10 = <<"daqui a %d dias"/utf8>>,
498 + replace_percent_d_with_int(_pipe@10, A@10);
499 +
500 + {future, week, 1} ->
501 + <<"daqui a 1 semana"/utf8>>;
502 +
503 + {future, week, A@11} ->
504 + _pipe@11 = <<"daqui a %d semanas"/utf8>>,
505 + replace_percent_d_with_int(_pipe@11, A@11);
506 +
507 + {future, month, 1} ->
508 + <<"daqui a 1 mês"/utf8>>;
509 +
510 + {future, month, A@12} ->
511 + _pipe@12 = <<"daqui a %d meses"/utf8>>,
512 + replace_percent_d_with_int(_pipe@12, A@12);
513 +
514 + {future, year, 1} ->
515 + <<"daqui a 1 ano"/utf8>>;
516 +
517 + {future, year, A@13} ->
518 + _pipe@13 = <<"daqui a %d anos"/utf8>>,
519 + replace_percent_d_with_int(_pipe@13, A@13)
520 + end.
  @@ -244,3 +244,38 @@ pub fn fr(tense: Tense, unit: Unit, amount: Int) -> String {
244 244 Future, Year, a -> "dans %d ans" |> replace_percent_d_with_int(a)
245 245 }
246 246 }
247 +
248 + /// Translations for Brazilian Portuguese.
249 + pub fn pt_br(tense: Tense, unit: Unit, amount: Int) -> String {
250 + case tense, unit, amount {
251 + _, Nanosecond, _ | _, Microsecond, _ | _, Millisecond, _ -> "agora mesmo"
252 + Past, Second, 1 -> "1 segundo atrás"
253 + Past, Second, a -> "%d segundos atrás" |> replace_percent_d_with_int(a)
254 + Past, Minute, 1 -> "1 minuto atrás"
255 + Past, Minute, a -> "%d minutos atrás" |> replace_percent_d_with_int(a)
256 + Past, Hour, 1 -> "1 hora atrás"
257 + Past, Hour, a -> "%d horas atrás" |> replace_percent_d_with_int(a)
258 + Past, Day, 1 -> "1 dia atrás"
259 + Past, Day, a -> "%d dias atrás" |> replace_percent_d_with_int(a)
260 + Past, Week, 1 -> "1 semana atrás"
261 + Past, Week, a -> "%d semanas atrás" |> replace_percent_d_with_int(a)
262 + Past, Month, 1 -> "1 mês atrás"
263 + Past, Month, a -> "%d meses atrás" |> replace_percent_d_with_int(a)
264 + Past, Year, 1 -> "1 ano atrás"
265 + Past, Year, a -> "%d anos atrás" |> replace_percent_d_with_int(a)
266 + Future, Second, 1 -> "daqui a 1 segundo"
267 + Future, Second, a -> "daqui a %d segundos" |> replace_percent_d_with_int(a)
268 + Future, Minute, 1 -> "daqui a 1 minuto"
269 + Future, Minute, a -> "daqui a %d minutos" |> replace_percent_d_with_int(a)
270 + Future, Hour, 1 -> "daqui a 1 hora"
271 + Future, Hour, a -> "daqui a %d horas" |> replace_percent_d_with_int(a)
272 + Future, Day, 1 -> "daqui a 1 dia"
273 + Future, Day, a -> "daqui a %d dias" |> replace_percent_d_with_int(a)
274 + Future, Week, 1 -> "daqui a 1 semana"
275 + Future, Week, a -> "daqui a %d semanas" |> replace_percent_d_with_int(a)
276 + Future, Month, 1 -> "daqui a 1 mês"
277 + Future, Month, a -> "daqui a %d meses" |> replace_percent_d_with_int(a)
278 + Future, Year, 1 -> "daqui a 1 ano"
279 + Future, Year, a -> "daqui a %d anos" |> replace_percent_d_with_int(a)
280 + }
281 + }