Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE!! [WF-2017] Allow overriding translations from parent components or app using pro… #388

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
350804a
Allow overriding translations from parent components or app using pro…
tcorral Jan 27, 2025
76e6f6a
Fix formatting
tcorral Jan 27, 2025
fdf40e1
Tests overriding works
tcorral Jan 27, 2025
4d456b3
Fix overriding translations
tcorral Jan 27, 2025
f1ca978
Override translations from parent and from the app level
tcorral Jan 27, 2025
6e22b2a
Update .npmrc
tcorral Jan 27, 2025
3f6b66a
Fix test issues
tcorral Jan 27, 2025
1a355d2
Fix test issues
tcorral Jan 27, 2025
f2c9521
Fix tests
tcorral Jan 27, 2025
b4068e3
Format
tcorral Jan 27, 2025
6899b9c
Fix lint, format, unit test
tcorral Jan 28, 2025
d8efb32
Fix warnings on e2e tests
tcorral Jan 28, 2025
85ca1ac
Apply suggested improvements to use spread operator
tcorral Jan 30, 2025
7a3b01a
Add colon right after the Template start for a proper usage of
tcorral Jan 30, 2025
1a13bd5
Remove to use just
tcorral Jan 30, 2025
40041ac
Change interfaces to be more clear by adding each key but keeping the…
tcorral Jan 30, 2025
c0505b9
Use translations-catalog.ts files to store providers, interfaces and …
tcorral Jan 30, 2025
416c692
Fix typo and explicitely say when component is not standalone
tcorral Jan 30, 2025
33eea0a
Fix test errors
tcorral Jan 30, 2025
a3c4ee1
Create catalogs for usages too
tcorral Jan 30, 2025
ffb4d31
Remove colon added by mistake
tcorral Jan 31, 2025
8f1f2ff
Remove testing text
tcorral Jan 31, 2025
4384962
Remove unneeded catalog
tcorral Jan 31, 2025
991dde7
Remove unneeded catalog
tcorral Jan 31, 2025
d68022e
Use Partial<> instead of using string | undefined on interface for tr…
tcorral Jan 31, 2025
c289fe1
Fix formatting issues
tcorral Jan 31, 2025
31b7eef
Hide label only for screen reader
tcorral Jan 31, 2025
49f2eda
Remove wrong comment
tcorral Feb 3, 2025
7ff80fa
Change default value for overridingTranslations
tcorral Feb 3, 2025
1c6cd39
Remove old way to setup default value for overridingTranslations
tcorral Feb 3, 2025
2e46598
Format
tcorral Feb 3, 2025
85ca39f
Remove unneeded private defaultTranslations property
tcorral Feb 3, 2025
305eec6
Merge branch 'main' into feature/wf-2017
RAJESH-GN Feb 4, 2025
2060f17
Abstract constructor behaviour to its own package
tcorral Feb 4, 2025
bd41d8f
Fix build output dir for shared-translations lib
daiscog Feb 4, 2025
8476d9b
Fix build issue
tcorral Feb 4, 2025
ac761e1
Add new tests for the new library
tcorral Feb 4, 2025
1e902dd
Revert changes to registry
tcorral Feb 4, 2025
2660d2b
Fix format
tcorral Feb 4, 2025
7a9f6be
Make translations interface more strict
tcorral Feb 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 56 additions & 104 deletions apps/golden-sample-app/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,24 @@
<nav class="bb-layout__topbar">
<!-- Skip to content -->
<button
aria-label="skip to content"
i18n-aria-label="
Move focus to beginning of content - 'skip to content'|This string is
used as the aria-label for a button that moves the focus to the
beginning of the content. It is presented to the user as an
accessibility feature to quickly navigate to the main content section.
This aria-label is located in the topbar area of the
layout.@@move-focus-to-beginning-of-content"
[ariaLabel]="translations['move-focus-to-beginning-of-content']"
class="bb-layout__skip-to-content"
(click)="focusMainContainer($event)"
i18n="
Skip to content - 'Skip to content'|This string is used as the text for
a button that moves the focus to the beginning of the content. It is
presented to the user as an accessibility feature to quickly navigate to
the main content section. This text is located in the topbar area of the
layout.@@skip-to-content"
>
Skip to Content
{{ translations['skip-to-content'] }}
</button>

<!-- Hamburger -->
<button
class="bb-layout__nav-expand-marker"
aria-label="Toggle sidebar"
i18n-aria-label="
Sidebar Toggler - 'Toggle sidebar'|This string is used as the aria-label
for a button that toggles the sidebar state. It is presented to the user
as an accessibility feature to indicate the button's function. This
aria-label is located in the topbar area of the
layout.@@bb-layout.sidebar_toggler"
[attr.aria-expanded]="layoutService.navigationExpanded$ | async"
[ariaLabel]="translations['bb-layout.sidebar_toggler']"
[ariaExpanded]="layoutService.navigationExpanded$ | async"
(click)="layoutService.toggleNav()"
>
<span class="bb-icon"></span>
<span class="sr-only">{{
translations['bb-layout.sidebar_toggler']
}}</span>
</button>

<!-- Logo -->
Expand All @@ -70,22 +54,16 @@
class="bb-layout__vertical-nav-item-icon"
name="payments"
></bb-icon-ui>
<span
class="bb-layout__horizontal-nav-item-description"
i18n="
Make transfer link - 'Make transfer'|This string is used as the
text for a link that navigates to the transfer page. It is
presented to the user as a navigation item in the horizontal
navigation bar. This text is located in the navigation items
section of the layout.@@main.transfer.link.text"
>
Make transfer
<span class="bb-layout__horizontal-nav-item-description">
{{ translations['main.transfer.link.text'] }}
</span>
</a>
</li>
<li
class="bb-layout__horizontal-nav-item"
*bbIfEntitlements="'EntPayments.AchPositivePay.create AND EntPayments.ManagePositivePay.create OR EntPayments.AchPositivePay.view'"
*bbIfEntitlements="
'EntPayments.AchPositivePay.create AND EntPayments.ManagePositivePay.create OR EntPayments.AchPositivePay.view'
"
>
<a
class="bb-layout__horizontal-nav-link"
Expand All @@ -101,17 +79,16 @@
name="transactions"
size="md"
></bb-icon-ui>
<span
class="bb-layout__horizontal-nav-item-description"
i18n="transactions list link@@main.transactions.link.text"
>
Entitlements test - No grouping.
<span class="bb-layout__horizontal-nav-item-description">
{{ translations['main.entitlements-test-no-grouping.text'] }}
</span>
</a>
</li>
<li
class="bb-layout__horizontal-nav-item"
*bbIfEntitlements="'EntPayments.AchPositivePay.create AND (EntPayments.ManagePositivePay.create OR EntPayments.AchPositivePay.view)'"
*bbIfEntitlements="
'EntPayments.AchPositivePay.create AND (EntPayments.ManagePositivePay.create OR EntPayments.AchPositivePay.view)'
"
>
<a
class="bb-layout__horizontal-nav-link"
Expand All @@ -127,17 +104,16 @@
name="transactions"
size="md"
></bb-icon-ui>
<span
class="bb-layout__horizontal-nav-item-description"
i18n="transactions list link@@main.transactions.link.text"
>
Entitlements test - Grouping.
<span class="bb-layout__horizontal-nav-item-description">
{{ translations['main.entitlements-test-grouping.text'] }}
</span>
</a>
</li>
<li
class="bb-layout__horizontal-nav-item"
*bbIfEntitlements="'((EntPayments.ManagePositivePay.create OR EntPayments.AchPositivePay.view) AND EntPayments.AchPositivePay.view) OR EntPayments.ManagePositivePay.create'"
*bbIfEntitlements="
'((EntPayments.ManagePositivePay.create OR EntPayments.AchPositivePay.view) AND EntPayments.AchPositivePay.view) OR EntPayments.ManagePositivePay.create'
"
>
<a
class="bb-layout__horizontal-nav-link"
Expand All @@ -153,17 +129,16 @@
name="transactions"
size="md"
></bb-icon-ui>
<span
class="bb-layout__horizontal-nav-item-description"
i18n="transactions list link@@main.transactions.link.text"
>
Entitlements test - Nested groups.
<span class="bb-layout__horizontal-nav-item-description">
{{ translations['main.entitlements-test-nested-groups.text'] }}
</span>
</a>
</li>
<li
class="bb-layout__horizontal-nav-item"
*bbIfEntitlements="'!((EntPayments.ManagePositivePay.create OR EntPayments.AchPositivePay.view) AND EntPayments.AchPositivePay.view) OR EntPayments.ManagePositivePay.create'"
*bbIfEntitlements="
'!((EntPayments.ManagePositivePay.create OR EntPayments.AchPositivePay.view) AND EntPayments.AchPositivePay.view) OR EntPayments.ManagePositivePay.create'
"
>
<a
class="bb-layout__horizontal-nav-link"
Expand All @@ -179,17 +154,20 @@
name="transactions"
size="md"
></bb-icon-ui>
<span
class="bb-layout__horizontal-nav-item-description"
i18n="transactions list link@@main.transactions.link.text"
>
Entitlements test - Using NOT operators on groups.
<span class="bb-layout__horizontal-nav-item-description">
{{
translations[
'main.entitlements-test-using-not-operators-on-groups.text'
]
}}
</span>
</a>
</li>
<li
class="bb-layout__horizontal-nav-item"
*bbIfEntitlements="'!(!(EntPayments.ManagePositivePay.create OR EntPayments.AchPositivePay.view) AND EntPayments.AchPositivePay.view) OR !EntPayments.ManagePositivePay.create'"
*bbIfEntitlements="
'!(!(EntPayments.ManagePositivePay.create OR EntPayments.AchPositivePay.view) AND EntPayments.AchPositivePay.view) OR !EntPayments.ManagePositivePay.create'
"
>
<a
class="bb-layout__horizontal-nav-link"
Expand All @@ -205,11 +183,12 @@
name="transactions"
size="md"
></bb-icon-ui>
<span
class="bb-layout__horizontal-nav-item-description"
i18n="transactions list link@@main.transactions.link.text"
>
Entitlements test - Using multiple NOT operators on groups.
<span class="bb-layout__horizontal-nav-item-description">
{{
translations[
'main.entitlements-test-using-multiple-not-operators-on-groups.text'
]
}}
</span>
</a>
</li>
Expand All @@ -231,16 +210,8 @@
name="transactions"
size="md"
></bb-icon-ui>
<span
class="bb-layout__horizontal-nav-item-description"
i18n="
Transactions list link - 'Transactions List'|This string is used
as the text for a link that navigates to the transactions list
page. It is presented to the user as a navigation item in the
horizontal navigation bar. This text is located in the navigation
items section of the layout.@@main.transactions.link.text"
>
Transactions List
<span class="bb-layout__horizontal-nav-item-description">
{{ translations['main.transactions.link.text'] }}
</span>
</a>
</li>
Expand All @@ -261,16 +232,8 @@
class="bb-layout__vertical-nav-item-icon"
name="note"
></bb-icon-ui>
<span
class="bb-layout__horizontal-nav-item-description"
i18n="
Positive pay link - 'Positive Pay'|This string is used as the text
for a link that navigates to the Positive Pay page. It is
presented to the user as a navigation item in the horizontal
navigation bar. This text is located in the navigation items
section of the layout.@@main.positive-pay.link.text"
>
Positive Pay
<span class="bb-layout__horizontal-nav-item-description">
{{ translations['main.positive-pay.link.text'] }}
</span>
</a>
</li>
Expand All @@ -292,16 +255,8 @@
name="verified-user"
></bb-icon-ui>

<span
class="bb-layout__horizontal-nav-item-description"
i18n="
Ach Positive pay link - 'ACH Positive Pay'|This string is used as
the text for a link that navigates to the ACH Positive Pay page.
It is presented to the user as a navigation item in the horizontal
navigation bar. This text is located in the navigation items
section of the layout.@@main.ach-positive-pay.link.text"
>
ACH Positive Pay
<span class="bb-layout__horizontal-nav-item-description">
{{ translations['main.ach-positive-pay.link.text'] }}
</span>
</a>
</li>
Expand All @@ -320,16 +275,8 @@
name="verified-user"
></bb-icon-ui>

<span
class="bb-layout__horizontal-nav-item-description"
i18n="
Make a Payment Link - 'Make internal payment'|This string is used
as the text for a link that navigates to the internal payment
page. It is presented to the user as a navigation item in the
horizontal navigation bar. This text is located in the navigation
items section of the layout.@@main.make-a-payment.link.text"
>
Make internal payment
<span class="bb-layout__horizontal-nav-item-description">
{{ translations['main.make-a-payment.link.text'] }}
</span>
</a>
</li>
Expand All @@ -350,7 +297,12 @@
></bb-icon-ui>
</a>

<a href="#" (click)="logout()" data-role="logout-btn" aria-label="Logout">
<a
href="#"
(click)="logout()"
data-role="logout-btn"
aria-label="Logout"
>
<bb-icon-ui
color="secondary"
data-role="notifications-icon"
Expand Down
11 changes: 11 additions & 0 deletions apps/golden-sample-app/src/app/app.component.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
.main-content {
padding: 20px;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border-width: 0;
}
2 changes: 2 additions & 0 deletions apps/golden-sample-app/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { OAuthService } from 'angular-oauth2-oidc';
import { of } from 'rxjs';
import { AppComponent } from './app.component';
import { environment } from '../environments/environment';
import { APP_TRANSLATIONS } from './translations-catalog';

describe('AppComponent', () => {
let fixture: ComponentFixture<AppComponent>;
Expand All @@ -27,6 +28,7 @@ describe('AppComponent', () => {
providers: [
{ provide: LayoutService, useValue: mockLayoutService },
{ provide: OAuthService, useValue: mockOAuthService },
{ provide: APP_TRANSLATIONS, useValue: {} },
],
schemas: [NO_ERRORS_SCHEMA],
}).compileComponents();
Expand Down
26 changes: 24 additions & 2 deletions apps/golden-sample-app/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Optional } from '@angular/core';
import { Component, Inject, Optional } from '@angular/core';
import { LayoutService } from '@backbase/ui-ang/layout';
import { triplets } from './services/entitlementsTriplets';
import { OAuthService } from 'angular-oauth2-oidc';
Expand All @@ -7,23 +7,45 @@ import {
Tracker,
} from '@backbase/foundation-ang/observability';
import { environment } from '../environments/environment';
import {
APP_TRANSLATIONS,
AppTranslations,
appTranslations,
} from './translations-catalog';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
standalone: false,
})
export class AppComponent {
triplets = triplets;
isAuthenticated = false;
private readonly defaultTranslations: AppTranslations = appTranslations;
public readonly translations: AppTranslations;

constructor(
private oAuthService: OAuthService,
private readonly oAuthService: OAuthService,
public layoutService: LayoutService,
@Inject(APP_TRANSLATIONS)
private readonly overridingTranslations: Partial<AppTranslations>,
Copy link
Collaborator

@RAJESH-GN RAJESH-GN Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why should this be Partial please try to have this as a last resource to have Partials as it might break so many things?

@Optional() private readonly tracker?: Tracker
) {
this.isAuthenticated =
environment.mockEnabled ?? oAuthService.hasValidAccessToken();
// If APP_TRANSLATIONS is not provided, set the default value as an empty object
this.overridingTranslations = this.overridingTranslations || {};

this.translations = {
...this.defaultTranslations,
...Object.fromEntries(
Object.entries(this.overridingTranslations).map(([key, value]) => [
key,
value ?? this.defaultTranslations[key],
])
),
};
}

logout(): void {
Expand Down
7 changes: 6 additions & 1 deletion apps/golden-sample-app/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { ApiSandboxInterceptor } from '../environments/api-sandbox-interceptor';
import packageInfo from 'package-json';
import { ThemeSwitcherModule } from './theme-switcher/theme-switcher.component.module';
import { ThemeManagerService } from './theme-switcher/theme-service';
import { APP_TRANSLATIONS } from './translations-catalog';

@NgModule({
declarations: [AppComponent],
Expand Down Expand Up @@ -94,7 +95,7 @@ import { ThemeManagerService } from './theme-switcher/theme-service';
ActivityMonitorModule,
],
providers: [
...(environment.mockProviders || []),
...(environment.mockProviders ?? []),
{ provide: AuthConfig, useValue: authConfig },
{
provide: HTTP_INTERCEPTORS,
Expand Down Expand Up @@ -184,6 +185,10 @@ import { ThemeManagerService } from './theme-switcher/theme-service';
},
ThemeManagerService,
provideHttpClient(withInterceptorsFromDi()),
{
provide: APP_TRANSLATIONS,
useValue: {},
},
],
})
export class AppModule {}
Loading