@yuneta/gobj-ui 7.32.4 → 7.32.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4436,8 +4436,11 @@ adds its ✕ (`yui_table_filter_clear()`). It does this when the table is
4436
4436
  built and again each time Tabulator builds the columns again. Call it right
4437
4437
  after `new Tabulator(...)`.
4438
4438
 
4439
- The app must define the keys `"rows"`, `"filter by column"` and `"clear"`,
4440
- and the paginator keys of `yui_tabulator_lang()`.
4439
+ The app must define the keys `"rows"`, `"rows_one"`, `"filter by column"`
4440
+ and `"clear"`, and the paginator keys of `yui_tabulator_lang()`. The count
4441
+ takes the plural of the number it goes with: `"rows_one"` for one row ("1
4442
+ fila"), `"rows"` for the others. Without `"rows_one"` i18next falls back to
4443
+ `"rows"`, and one row reads "1 filas".
4441
4444
 
4442
4445
  Two things to look at when you apply it:
4443
4446
 
@@ -62504,8 +62504,8 @@ function create_tabulator(gobj) {
62504
62504
  } catch (e) {
62505
62505
  total = n;
62506
62506
  }
62507
- if (typeof total === "number" && total > n) $rc.textContent = `${n} / ${total} ${(0, i18next.t)("rows")}`;
62508
- else $rc.textContent = `${n} ${(0, i18next.t)("rows")}`;
62507
+ if (typeof total === "number" && total > n) $rc.textContent = `${n} / ${total} ${(0, i18next.t)("rows", { count: total })}`;
62508
+ else $rc.textContent = `${n} ${(0, i18next.t)("rows", { count: n })}`;
62509
62509
  }
62510
62510
  tabulator.on("columnsLoaded", function() {
62511
62511
  yui_tabulator_name_filters(tabulator, i18next.t);
@@ -62499,8 +62499,8 @@ function create_tabulator(gobj) {
62499
62499
  } catch (e) {
62500
62500
  total = n;
62501
62501
  }
62502
- if (typeof total === "number" && total > n) $rc.textContent = `${n} / ${total} ${t("rows")}`;
62503
- else $rc.textContent = `${n} ${t("rows")}`;
62502
+ if (typeof total === "number" && total > n) $rc.textContent = `${n} / ${total} ${t("rows", { count: total })}`;
62503
+ else $rc.textContent = `${n} ${t("rows", { count: n })}`;
62504
62504
  }
62505
62505
  tabulator.on("columnsLoaded", function() {
62506
62506
  yui_tabulator_name_filters(tabulator, t);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.32.4",
3
+ "version": "7.32.5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/gobj-ui.cjs.js",
@@ -1896,10 +1896,12 @@ function create_tabulator(gobj)
1896
1896
  total = n;
1897
1897
  }
1898
1898
  }
1899
+ /* The word in the plural of the number it goes with: "1 fila",
1900
+ * "13 filas" (`rows_one` / `rows`). Up to 7.32.4, "1 filas". */
1899
1901
  if(typeof total === "number" && total > n) {
1900
- $rc.textContent = `${n} / ${total} ${t("rows")}`;
1902
+ $rc.textContent = `${n} / ${total} ${t("rows", {count: total})}`;
1901
1903
  } else {
1902
- $rc.textContent = `${n} ${t("rows")}`;
1904
+ $rc.textContent = `${n} ${t("rows", {count: n})}`;
1903
1905
  }
1904
1906
  }
1905
1907
 
@@ -41,11 +41,14 @@
41
41
  * and a parent that fails hides the children that match.
42
42
  *
43
43
  * The row count needs the key "rows" in the app (every app
44
- * that shows a treedb table has it already).
44
+ * that shows a treedb table has it already), and "rows_one"
45
+ * for one row ("1 row", "1 fila").
45
46
  *
46
47
  * Copyright (c) 2026, ArtGins.
47
48
  * All Rights Reserved.
48
49
  ***********************************************************************/
50
+ import i18next from "i18next";
51
+
49
52
  import {yui_tabulator_name_filters} from "./yui_tabulator_i18n.js";
50
53
  import {yui_table_filter_clear} from "./yui_table_filter_clear.js";
51
54
 
@@ -64,6 +67,14 @@ const YUI_TABLE_FILTER_MIN_WIDTH = 150;
64
67
  const CONTROL_FORMATTERS = ["rowSelection", "handle", "responsiveCollapse", "buttonCross"];
65
68
 
66
69
 
70
+ /***************************************************************
71
+ * The word of the row count, in the app's language and plural.
72
+ ***************************************************************/
73
+ function rows_word(count)
74
+ {
75
+ return i18next.t("rows", {count: count, defaultValue: count === 1 ? "row" : "rows"});
76
+ }
77
+
67
78
  /***************************************************************
68
79
  * The row count of the footer.
69
80
  *
@@ -72,10 +83,13 @@ const CONTROL_FORMATTERS = ["rowSelection", "handle", "responsiveCollapse", "but
72
83
  * count: the rows the filters leave, all pages together. With a
73
84
  * filter on, the count says both: "12 / 27 rows".
74
85
  *
75
- * The number is data; the word comes from the table's locale
76
- * (`pagination.counter.rows`, which `yui_tabulator_lang()` fills
77
- * with the app's "rows"), and `langBind` changes it again when
78
- * `yui_tabulator_relocalize()` installs a new language.
86
+ * The number is data. The word is the app's plural of "rows"
87
+ * (`rows_one` for one, `rows` for the others; i18next falls back to
88
+ * `rows` when the form is missing), for the number it goes with: the
89
+ * total when there are two. Up to 7.32.4 it was one word for every
90
+ * number, "1 filas". `langBind` on the table's locale is only the
91
+ * trigger: `yui_tabulator_relocalize()` installs a new language and
92
+ * the word is asked again.
79
93
  *
80
94
  * Returns a DOM node, never a string: Tabulator puts a string in
81
95
  * with `innerHTML`.
@@ -103,11 +117,11 @@ function rows_counter(page_size, current_row, current_page, total_rows)
103
117
 
104
118
  let $word = document.createElement("span");
105
119
  $word.className = "YUI_TABLE_COUNT_WORD";
106
- $word.textContent = "rows";
120
+ $word.textContent = rows_word(all);
107
121
  let localize = this && this.table && this.table.modules ? this.table.modules.localize : null;
108
122
  if(localize && typeof localize.langBind === "function") {
109
- localize.langBind("pagination|counter|rows", (value) => {
110
- $word.textContent = value;
123
+ localize.langBind("pagination|counter|rows", () => {
124
+ $word.textContent = rows_word(all);
111
125
  });
112
126
  }
113
127
 
@@ -13,6 +13,13 @@ import {install_dom_double} from "../test/dom_double.js";
13
13
 
14
14
  install_dom_double();
15
15
 
16
+ import i18next from "i18next";
17
+
18
+ await i18next.init({lng: "es", resources: {
19
+ es: {translation: {rows: "filas", rows_one: "fila"}},
20
+ en: {translation: {rows: "rows", rows_one: "row"}}
21
+ }});
22
+
16
23
  import {
17
24
  YUI_TABLE_FILTER_MIN_WIDTH,
18
25
  yui_table_paging,
@@ -48,7 +55,7 @@ describe("the paging", () => {
48
55
  });
49
56
 
50
57
  describe("the row count", () => {
51
- function page_module(word)
58
+ function page_module()
52
59
  {
53
60
  let bindings = [];
54
61
  return {
@@ -57,8 +64,8 @@ describe("the row count", () => {
57
64
  modules: {
58
65
  localize: {
59
66
  langBind(path, cb) {
60
- bindings.push(path);
61
- cb(word);
67
+ bindings.push({path, cb});
68
+ cb("ignored");
62
69
  }
63
70
  }
64
71
  }
@@ -66,39 +73,50 @@ describe("the row count", () => {
66
73
  };
67
74
  }
68
75
 
69
- test("says every active row, all pages together, in the table's language", () => {
76
+ test("says every active row, all pages together, in the app's plural", () => {
70
77
  let counter = yui_table_paging().paginationCounter;
71
- let page = page_module("filas");
78
+ let page = page_module();
72
79
  let $el = counter.call(page, 25, 26, 2, 113, 5);
73
80
  expect($el.textContent).toBe("113 filas");
74
- expect(page.bindings).toEqual(["pagination|counter|rows"]);
81
+ expect(page.bindings.map((b) => b.path)).toEqual(["pagination|counter|rows"]);
82
+ expect(counter.call(page_module(), 25, 1, 1, 1, 1).textContent).toBe("1 fila");
83
+ });
84
+
85
+ test("a language change asks the word again", async () => {
86
+ let counter = yui_table_paging().paginationCounter;
87
+ let page = page_module();
88
+ let $el = counter.call(page, 25, 1, 1, 1, 1);
89
+ await i18next.changeLanguage("en");
90
+ page.bindings[0].cb("ignored");
91
+ expect($el.textContent).toBe("1 row");
92
+ await i18next.changeLanguage("es");
75
93
  });
76
94
 
77
95
  test("an empty table says 0", () => {
78
96
  let counter = yui_table_paging().paginationCounter;
79
- let $el = counter.call(page_module("rows"), 25, 0, 1, 0, 0);
80
- expect($el.textContent).toBe("0 rows");
97
+ let $el = counter.call(page_module(), 25, 0, 1, 0, 0);
98
+ expect($el.textContent).toBe("0 filas");
81
99
  });
82
100
 
83
101
  test("is a node, never a string Tabulator would put in as html", () => {
84
102
  let counter = yui_table_paging().paginationCounter;
85
- let $el = counter.call(page_module("rows"), 25, 1, 1, 3, 1);
103
+ let $el = counter.call(page_module(), 25, 1, 1, 3, 1);
86
104
  expect(typeof $el).toBe("object");
87
105
  expect($el.className).toBe("YUI_TABLE_COUNT");
88
106
  });
89
107
 
90
108
  test("with a filter on, the rows it leaves of the rows the table holds", () => {
91
109
  let counter = yui_table_paging().paginationCounter;
92
- let page = page_module("rows");
110
+ let page = page_module();
93
111
  page.table.getDataCount = () => 27;
94
- expect(counter.call(page, 25, 1, 1, 12, 1).textContent).toBe("12 / 27 rows");
95
- expect(counter.call(page, 25, 1, 1, 27, 2).textContent).toBe("27 rows");
112
+ expect(counter.call(page, 25, 1, 1, 12, 1).textContent).toBe("12 / 27 filas");
113
+ expect(counter.call(page, 25, 1, 1, 27, 2).textContent).toBe("27 filas");
96
114
  });
97
115
 
98
- test("without a localize module it still counts, in English", () => {
116
+ test("without a localize module it still counts", () => {
99
117
  let counter = yui_table_paging().paginationCounter;
100
118
  let $el = counter.call({}, 25, 1, 1, 3, 1);
101
- expect($el.textContent).toBe("3 rows");
119
+ expect($el.textContent).toBe("3 filas");
102
120
  });
103
121
  });
104
122