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

feat(action,action-bar, action-group,action-pad): add built in translation support #5423

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
096f757
feat: add built-in translations
jcfranco Jul 18, 2022
daf9def
add bundles
jcfranco Aug 2, 2022
d284ef4
remove obsolete folder
jcfranco Aug 2, 2022
62fd6ee
add type generator
anveshmekala Aug 5, 2022
e798c7d
rename type's file
anveshmekala Aug 15, 2022
d00849d
delete non-t9n file
jcfranco Aug 16, 2022
5e37ae3
commit lock file
jcfranco Aug 16, 2022
2320e1f
rename type generating script and tidy up
jcfranco Aug 16, 2022
a8fd161
regenerate interface files
jcfranco Aug 16, 2022
472e6a1
update color-picker file
jcfranco Aug 16, 2022
cb7fb56
add missing value-list entries
jcfranco Aug 16, 2022
79a79e0
inline common strings until we have common bundle wired up
jcfranco Aug 16, 2022
64bd8dc
revert unnecessary tsconfig changes
jcfranco Aug 16, 2022
c66c420
update interface files
jcfranco Aug 16, 2022
14e2bc2
Merge branch 'master' into jcfranco/4961-add-built-in-localization-to…
anveshmekala Aug 19, 2022
48a584c
add util to fetchbundles and supported locale
anveshmekala Aug 19, 2022
bd0d359
feedback changes
anveshmekala Aug 19, 2022
b983d2d
more cleanup
anveshmekala Aug 19, 2022
9fd8305
remove intl default value validation in e2e
anveshmekala Aug 22, 2022
78d2987
sync en.json with en-US.json bundle
anveshmekala Aug 24, 2022
06252c7
rename script
anveshmekala Aug 24, 2022
b78dd81
refactor script file
anveshmekala Aug 24, 2022
fd58f43
remove console.log
anveshmekala Aug 24, 2022
500fe85
refactor & add back types to intl props in colorpicker
anveshmekala Aug 30, 2022
7f7d567
add util method for string over rides
anveshmekala Sep 1, 2022
9ae38ac
Merge branch 'master' into jcfranco/4961-add-built-in-localization-to…
anveshmekala Sep 2, 2022
3b113c0
tidy up
jcfranco Sep 4, 2022
335f397
simplify t9n pattern
jcfranco Sep 4, 2022
36a4a6e
fix issue caused by type + interface TS shape confusion
jcfranco Sep 4, 2022
3e3aa3b
support nb&no for norwegian locale
anveshmekala Sep 6, 2022
3a61c52
add cache for stringBundle fetch
anveshmekala Sep 7, 2022
94b8122
tidy up
jcfranco Sep 7, 2022
8cd1c5c
drop intl from string bundle keys
jcfranco Sep 7, 2022
1f31505
update scripts to use messages as string bundle name
jcfranco Sep 7, 2022
19c2458
rename bundles
jcfranco Sep 7, 2022
50059df
rename interface props
jcfranco Sep 8, 2022
1c575c9
add t9ntest util methods
anveshmekala Sep 9, 2022
8782977
Merge branch 'master' into jcfranco/4961-add-built-in-localization-to…
anveshmekala Sep 12, 2022
24f19e5
Merge branch 'master' into jcfranco/4961-add-built-in-localization-to…
benelan Sep 13, 2022
e327282
restore intlProp watching to pattern
jcfranco Sep 9, 2022
159de44
use extended mutation observer to simplify unobserving
jcfranco Sep 9, 2022
45f909c
add intl prop watcher doc
jcfranco Sep 16, 2022
0cd2f82
add support for cascading lang
jcfranco Sep 16, 2022
7517e84
Merge branch 'master' into jcfranco/4961-add-built-in-localization-to…
jcfranco Sep 16, 2022
99f9132
tidy up
jcfranco Sep 16, 2022
36fb1f1
update conventions doc with pattern info
jcfranco Sep 16, 2022
2c3aa53
update doc
jcfranco Sep 16, 2022
a1d3060
merge master
jcfranco Sep 17, 2022
9b8d75c
drop and ignore generated d.ts files and tweak messages type names
jcfranco Sep 17, 2022
8daebbe
wire up interface generation before build
jcfranco Sep 17, 2022
bed440d
merge w other
jcfranco Sep 17, 2022
60a6316
refactor localized components pattern
jcfranco Sep 17, 2022
42433af
refactor t9n pattern to work w/ localized component
jcfranco Sep 17, 2022
ce299db
tidy up
jcfranco Sep 21, 2022
b041d48
fix utils depending on defined locale and not placeholder one
jcfranco Sep 21, 2022
d7757ea
consolidate t9n tests and make intl prop merging happen at run time
jcfranco Sep 21, 2022
f43f4b3
Updated Pseudo i18n - @jian9413
jona7150 Sep 23, 2022
700a805
ensure connectLocale happens before code that depends on locale
jcfranco Oct 5, 2022
9b52cc7
merge master
jcfranco Oct 5, 2022
9354553
cherry pick lang inheritance changes
jcfranco Oct 6, 2022
443e414
update doc
jcfranco Oct 6, 2022
64ff33b
make lang lookup more robust
jcfranco Oct 7, 2022
6c8f499
update doc
jcfranco Oct 7, 2022
47cfeb7
feat(action): add built-in localization support
anveshmekala Oct 7, 2022
72443e9
change effectiveLocale prop to state
anveshmekala Oct 7, 2022
5b6b02a
localizify action-bar, action-group & action-pad components
anveshmekala Oct 7, 2022
0f105b4
Merge branch 'master' into anveshmekala/4961-action-add-built-in-tran…
anveshmekala Oct 18, 2022
7b501c2
fix test errors
anveshmekala Oct 18, 2022
c2d1805
Merge branch 'master' into anveshmekala/4961-action-add-built-in-tran…
anveshmekala Oct 19, 2022
3c1e02d
fix test error
anveshmekala Oct 19, 2022
afc0080
revert color-picker changes
anveshmekala Oct 19, 2022
e424bb9
Merge branch 'master' into anveshmekala/4961-action-add-built-in-tran…
anveshmekala Oct 19, 2022
75f7aeb
fix test errors
anveshmekala Oct 19, 2022
866ce16
Merge branch 'master' into anveshmekala/4961-action-add-built-in-tran…
anveshmekala Oct 19, 2022
37d025c
Merge branch 'master' into anveshmekala/4961-action-add-built-in-tran…
anveshmekala Oct 19, 2022
87798c1
Merge branch 'master' into anveshmekala/4961-action-add-built-in-tran…
anveshmekala Oct 20, 2022
82bb5d5
fix build errors
anveshmekala Oct 20, 2022
fd0f24b
Merge branch 'anveshmekala/4961-add-built-in-pseudo-translations' int…
anveshmekala Oct 20, 2022
5b34072
Merge branch 'anveshmekala/4961-add-built-in-pseudo-translations' int…
anveshmekala Oct 20, 2022
b70bf8a
remove browser build conditional
anveshmekala Oct 26, 2022
7a2ca31
clean up
anveshmekala Oct 26, 2022
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
4 changes: 3 additions & 1 deletion src/components/action-bar/action-bar.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { newE2EPage } from "@stencil/core/testing";
import { accessible, defaults, focusable, hidden, reflects, renders, slots } from "../../tests/commonTests";
import { accessible, defaults, focusable, hidden, reflects, renders, slots, t9n } from "../../tests/commonTests";
import { CSS, SLOTS } from "./resources";
import { overflowActionsDebounceInMs } from "./utils";
import { html } from "../../../support/formatting";
Expand Down Expand Up @@ -382,4 +382,6 @@ describe("calcite-action-bar", () => {
expect(await page.findAll(slottedActionsSelector)).toHaveLength(2);
});
});

it("supports translation", () => t9n("calcite-action-bar"));
});
78 changes: 59 additions & 19 deletions src/components/action-bar/action-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import {
Watch,
h,
VNode,
Method
Method,
State
} from "@stencil/core";
import { Position, Scale, Layout } from "../interfaces";
import { ExpandToggle, toggleChildActionText } from "../functional/ExpandToggle";
import { CSS, SLOTS, TEXT } from "./resources";
import { CSS, SLOTS } from "./resources";
import { getSlotted, focusElement } from "../../utils/dom";
import {
geActionDimensions,
Expand All @@ -28,6 +29,15 @@ import {
disconnectConditionalSlotComponent,
ConditionalSlotComponent
} from "../../utils/conditionalSlot";
import { connectLocalized, disconnectLocalized, LocalizedComponent } from "../../utils/locale";
import {
connectMessages,
disconnectMessages,
setUpMessages,
T9nComponent,
updateMessages
} from "../../utils/t9n";
import { Messages } from "./assets/action-bar/t9n";

/**
* @slot - A slot for adding `calcite-action`s that will appear at the top of the action bar.
Expand All @@ -37,9 +47,10 @@ import {
@Component({
tag: "calcite-action-bar",
styleUrl: "action-bar.scss",
shadow: true
shadow: true,
assetsDirs: ["assets"]
})
export class ActionBar implements ConditionalSlotComponent {
export class ActionBar implements ConditionalSlotComponent, LocalizedComponent, T9nComponent {
// --------------------------------------------------------------------------
//
// Properties
Expand Down Expand Up @@ -69,11 +80,15 @@ export class ActionBar implements ConditionalSlotComponent {

/**
* Specifies the label of the expand icon when the component is collapsed.
*
* @deprecated - translations are now built-in, if you need to override a string, please use `messageOverrides`
*/
@Prop() intlExpand?: string;

/**
* Specifies the label of the collapse icon when the component is expanded.
*
* @deprecated - translations are now built-in, if you need to override a string, please use `messageOverrides`
*/
@Prop() intlCollapse?: string;

Expand Down Expand Up @@ -104,6 +119,26 @@ export class ActionBar implements ConditionalSlotComponent {
*/
@Prop({ reflect: true }) scale: Scale;

/**
* Made into a prop for testing purposes only
*
* @internal
*/
@Prop({ mutable: true }) messages: Messages;

/**
* Use this property to override individual strings used by the component.
*/
@Prop({ mutable: true }) messageOverrides: Partial<Messages>;

@Watch("intlCollapse")
@Watch("intlExpand")
@Watch("defaultMessages")
@Watch("messageOverrides")
onMessagesChange(): void {
/* wired up by t9n util */
}

// --------------------------------------------------------------------------
//
// Events
Expand Down Expand Up @@ -133,6 +168,15 @@ export class ActionBar implements ConditionalSlotComponent {

expandToggleEl: HTMLCalciteActionElement;

@State() effectiveLocale: string;

@Watch("effectiveLocale")
effectiveLocaleChange(): void {
updateMessages(this, this.effectiveLocale);
}

@State() defaultMessages: Messages;

// --------------------------------------------------------------------------
//
// Lifecycle
Expand All @@ -146,6 +190,8 @@ export class ActionBar implements ConditionalSlotComponent {
connectedCallback(): void {
const { el, expanded } = this;

connectLocalized(this);
connectMessages(this);
toggleChildActionText({ parent: el, expanded });

this.mutationObserver?.observe(el, { childList: true, subtree: true });
Expand All @@ -158,10 +204,16 @@ export class ActionBar implements ConditionalSlotComponent {
connectConditionalSlotComponent(this);
}

async componentWillLoad(): Promise<void> {
await setUpMessages(this);
}

disconnectedCallback(): void {
this.mutationObserver?.disconnect();
this.resizeObserver?.disconnect();
disconnectConditionalSlotComponent(this);
disconnectLocalized(this);
disconnectMessages(this);
}

// --------------------------------------------------------------------------
Expand Down Expand Up @@ -277,28 +329,16 @@ export class ActionBar implements ConditionalSlotComponent {
// --------------------------------------------------------------------------

renderBottomActionGroup(): VNode {
const {
expanded,
expandDisabled,
intlExpand,
intlCollapse,
el,
position,
toggleExpand,
scale,
layout
} = this;
const { expanded, expandDisabled, el, position, toggleExpand, scale, layout, messages } = this;

const tooltip = getSlotted(el, SLOTS.expandTooltip) as HTMLCalciteTooltipElement;
const expandLabel = intlExpand || TEXT.expand;
const collapseLabel = intlCollapse || TEXT.collapse;

const expandToggleNode = !expandDisabled ? (
<ExpandToggle
el={el}
expanded={expanded}
intlCollapse={collapseLabel}
intlExpand={expandLabel}
intlCollapse={messages.collapse}
intlExpand={messages.expand}
position={position}
ref={this.setExpandToggleRef}
scale={scale}
Expand Down
5 changes: 0 additions & 5 deletions src/components/action-bar/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,3 @@ export const SLOTS = {
bottomActions: "bottom-actions",
expandTooltip: "expand-tooltip"
};

export const TEXT = {
expand: "Expand",
collapse: "Collapse"
};
4 changes: 3 additions & 1 deletion src/components/action-group/action-group.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { accessible, hidden, renders, slots } from "../../tests/commonTests";
import { accessible, hidden, renders, slots, t9n } from "../../tests/commonTests";
import { newE2EPage } from "@stencil/core/testing";
import { SLOTS } from "./resources";

Expand Down Expand Up @@ -28,4 +28,6 @@ describe("calcite-action-group", () => {

expect(await menu.getProperty("scale")).toBe("l");
});

it("support translation", () => t9n("calcite-action-group"));
});
64 changes: 56 additions & 8 deletions src/components/action-group/action-group.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Element, h, Prop, Watch } from "@stencil/core";
import { ICONS, SLOTS, TEXT } from "./resources";
import { Fragment, VNode } from "@stencil/core/internal";
import { ICONS, SLOTS } from "./resources";
import { Fragment, State, VNode } from "@stencil/core/internal";
import { getSlotted } from "../../utils/dom";
import { SLOTS as ACTION_MENU_SLOTS } from "../action-menu/resources";
import { Columns, Layout, Scale } from "../interfaces";
Expand All @@ -10,6 +10,15 @@ import {
disconnectConditionalSlotComponent
} from "../../utils/conditionalSlot";
import { CalciteActionMenuCustomEvent } from "../../components";
import { connectLocalized, disconnectLocalized, LocalizedComponent } from "../../utils/locale";
import {
connectMessages,
disconnectMessages,
setUpMessages,
T9nComponent,
updateMessages
} from "../../utils/t9n";
import { Messages } from "./assets/action-group/t9n";

/**
* @slot - A slot for adding a group of `calcite-action`s.
Expand All @@ -19,9 +28,10 @@ import { CalciteActionMenuCustomEvent } from "../../components";
@Component({
tag: "calcite-action-group",
styleUrl: "action-group.scss",
shadow: true
shadow: true,
assetsDirs: ["assets"]
})
export class ActionGroup implements ConditionalSlotComponent {
export class ActionGroup implements ConditionalSlotComponent, LocalizedComponent, T9nComponent {
// --------------------------------------------------------------------------
//
// Properties
Expand Down Expand Up @@ -50,6 +60,8 @@ export class ActionGroup implements ConditionalSlotComponent {

/**
* Specifies a text string for the `calcite-action-menu`.
*
* @deprecated - translations are now built-in, if you need to override a string, please use `messageOverrides`
*/
@Prop() intlMore?: string;

Expand All @@ -63,13 +75,41 @@ export class ActionGroup implements ConditionalSlotComponent {
*/
@Prop({ reflect: true }) scale: Scale;

/**
* Made into a prop for testing purposes only
*
* @internal
*/
@Prop({ mutable: true }) messages: Messages;

/**
* Use this property to override individual strings used by the component.
*/
@Prop({ mutable: true }) messageOverrides: Partial<Messages>;

@Watch("intlMore")
@Watch("defaultMessages")
@Watch("messageOverrides")
onMessagesChange(): void {
/* wired up by t9n util */
}

// --------------------------------------------------------------------------
//
// Private Properties
//
// --------------------------------------------------------------------------
@Element()
el: HTMLCalciteActionGroupElement;

@Element() el: HTMLCalciteActionGroupElement;
@State() effectiveLocale = "";

@Watch("effectiveLocale")
effectiveLocaleChange(): void {
updateMessages(this, this.effectiveLocale);
}

@State() defaultMessages: Messages;

// --------------------------------------------------------------------------
//
Expand All @@ -78,13 +118,21 @@ export class ActionGroup implements ConditionalSlotComponent {
// --------------------------------------------------------------------------

connectedCallback(): void {
connectLocalized(this);
connectMessages(this);
connectConditionalSlotComponent(this);
}

disconnectedCallback(): void {
disconnectLocalized(this);
disconnectMessages(this);
disconnectConditionalSlotComponent(this);
}

async componentWillLoad(): Promise<void> {
await setUpMessages(this);
}

// --------------------------------------------------------------------------
//
// Component Methods
Expand All @@ -99,15 +147,15 @@ export class ActionGroup implements ConditionalSlotComponent {
}

renderMenu(): VNode {
const { el, expanded, intlMore, menuOpen, scale, layout } = this;
const { el, expanded, menuOpen, scale, layout, messages } = this;

const hasMenuItems = getSlotted(el, SLOTS.menuActions);

return hasMenuItems ? (
<calcite-action-menu
expanded={expanded}
flipPlacements={["left", "right"]}
label={intlMore || TEXT.more}
label={messages.more}
onCalciteActionMenuOpenChange={this.setMenuOpen}
open={menuOpen}
placement={layout === "horizontal" ? "bottom-leading" : "leading-start"}
Expand All @@ -117,7 +165,7 @@ export class ActionGroup implements ConditionalSlotComponent {
icon={ICONS.menu}
scale={scale}
slot={ACTION_MENU_SLOTS.trigger}
text={intlMore || TEXT.more}
text={messages.more}
textEnabled={expanded}
/>
<slot name={SLOTS.menuActions} />
Expand Down
4 changes: 0 additions & 4 deletions src/components/action-group/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ export const SLOTS = {
menuTooltip: "menu-tooltip"
};

export const TEXT = {
more: "More"
};

export const ICONS = {
menu: "ellipsis"
};
4 changes: 3 additions & 1 deletion src/components/action-pad/action-pad.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { newE2EPage } from "@stencil/core/testing";
import { accessible, defaults, focusable, hidden, reflects, renders, slots } from "../../tests/commonTests";
import { accessible, defaults, focusable, hidden, reflects, renders, slots, t9n } from "../../tests/commonTests";
import { CSS, SLOTS } from "./resources";
import { html } from "../../../support/formatting";

Expand Down Expand Up @@ -250,4 +250,6 @@ describe("calcite-action-pad", () => {

expect(await button.getProperty("scale")).toBe("l");
});

it("supports translation", () => t9n("calcite-action-pad"));
});
Loading