@rivinia/i18n 0.3.1 → 0.3.3

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
@@ -8,7 +8,7 @@ JSON dictionaries, inline translations, RTL/LTR document attributes, lazy
8
8
  loaders, ICU plural/select messages, browser-language detection, and
9
9
  ECMAScript internationalization number/date formatting.
10
10
 
11
- - Prepared patch: **0.3.1** (latest published: **0.3.0**)
11
+ - Package version: **0.3.2**
12
12
  - Peer dependency: **`@angular/core` `^22.0.0`**
13
13
  - No `tslib` or `HttpClient` peer dependency. Built-in loaders use `fetch`.
14
14
 
@@ -134,19 +134,8 @@ import { i18nConfig } from './i18n.config';
134
134
 
135
135
  @Component({
136
136
  selector: 'app-header',
137
- standalone: true,
138
137
  imports: [RTranslatePipe],
139
- template: `
140
- @if (i18n.ready()) {
141
- <p>{{ i18n.translate({ en: 'Welcome', ar: 'أهلاً' }) }}</p>
142
- <p>{{ 'booking.seats' | rTranslate: { count: seatCount } }}</p>
143
- <p>{{ i18n.formatNumber(price, { style: 'currency', currency: 'USD' }) }}</p>
144
- <button type="button" (click)="i18n.setLanguage('ar')">العربية</button>
145
- <button type="button" (click)="i18n.setLanguage('en')">English</button>
146
- } @else {
147
- <p>Loading…</p>
148
- }
149
- `,
138
+ templateUrl: './header.component.html',
150
139
  })
151
140
  export class HeaderComponent {
152
141
  readonly i18n = i18nConfig.inject();
@@ -155,6 +144,19 @@ export class HeaderComponent {
155
144
  }
156
145
  ```
157
146
 
147
+ ```html
148
+ <!-- src/app/header.component.html -->
149
+ @if (i18n.ready()) {
150
+ <p>{{ i18n.translate({ en: 'Welcome', ar: 'أهلاً' }) }}</p>
151
+ <p>{{ 'booking.seats' | rTranslate: { count: seatCount } }}</p>
152
+ <p>{{ i18n.formatNumber(price, { style: 'currency', currency: 'USD' }) }}</p>
153
+ <button type="button" (click)="i18n.setLanguage('ar')">العربية</button>
154
+ <button type="button" (click)="i18n.setLanguage('en')">English</button>
155
+ } @else {
156
+ <p>Loading…</p>
157
+ }
158
+ ```
159
+
158
160
  For key lookup, `translate('booking.seats', { count: 3 })` is also available.
159
161
  Missing keys return the key itself, or the supplied fallback:
160
162
  `translate('missing.key', 'Not available')`. Inline language maps fall back to
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivinia/i18n",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Headless language manager for Angular: signals, RTL, loaders, ICU plurals, browser detection, Intl formatting.",
5
5
  "keywords": [
6
6
  "angular",
@@ -12,6 +12,7 @@
12
12
  ],
13
13
  "license": "MIT",
14
14
  "peerDependencies": {
15
+ "@angular-devkit/schematics": "^22.0.0",
15
16
  "@angular/core": "^22.0.0"
16
17
  },
17
18
  "sideEffects": false,
@@ -94,7 +94,7 @@ function ngAdd(options) {
94
94
  throw new schematics_1.SchematicsException(`[rivinia/i18n] ${configPath} is empty.`);
95
95
  }
96
96
  let changed = false;
97
- if (!content.includes(PROVIDE_IMPORT)) {
97
+ if (!importsValue(content, '@rivinia/i18n', 'provideRiviniaI18n')) {
98
98
  content = insertAfterLastImport(content, PROVIDE_IMPORT);
99
99
  changed = true;
100
100
  }
@@ -160,3 +160,33 @@ function insertProvider(content, call) {
160
160
  const at = match.index + match[0].length;
161
161
  return `${content.slice(0, at)}\n ${call},${content.slice(at)}`;
162
162
  }
163
+ /**
164
+ * Whether the file already binds `symbol` as a VALUE imported from `module`.
165
+ *
166
+ * A plain `content.includes(IMPORT_LINE)` recognises only ONE shape of the
167
+ * import — `import { symbol } from 'module';`. An app that imports the
168
+ * symbol beside others (`import { other, symbol } from 'module';`) would be
169
+ * given a SECOND import of the same symbol, and its build would then fail
170
+ * with "Duplicate identifier" (TS2300).
171
+ *
172
+ * An aliased or a type-only import does not bind the name we need, so it
173
+ * does not count as present.
174
+ */
175
+ function importsValue(content, module, symbol) {
176
+ const pattern = /import\s+(?:type\s+)?\{([^}]*)\}\s*from\s*['"]([^'"]+)['"]/g;
177
+ for (const match of content.matchAll(pattern)) {
178
+ if (match[2] !== module)
179
+ continue;
180
+ if (/^\s*import\s+type\s/.test(match[0]))
181
+ continue; // a type-only import
182
+ for (const entry of match[1].split(',')) {
183
+ const raw = entry.trim();
184
+ if (!raw || /^type\s/.test(raw))
185
+ continue; // a type-only specifier
186
+ const local = raw.split(/\s+as\s+/).pop().trim();
187
+ if (local === symbol)
188
+ return true;
189
+ }
190
+ }
191
+ return false;
192
+ }