Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 9 additions & 1 deletion fluent-bundle/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export type TextTransform = (text: string) => string;
type NativeValue = string | number | Date;
export type FluentVariable = FluentValue | NativeValue;

const noTransform: TextTransform = (
text => text
);

/**
* Message bundles are single-language stores of translation resources. They are
* responsible for formatting message values and attributes to strings.
Expand All @@ -23,6 +27,7 @@ export class FluentBundle {
public _functions: Record<string, FluentFunction>;
public _useIsolating: boolean;
public _transform: TextTransform;
public _transformPlaceable: TextTransform;
public _intls: IntlCache;

/**
Expand Down Expand Up @@ -59,11 +64,13 @@ export class FluentBundle {
{
functions,
useIsolating = true,
transform = (v: string): string => v
transform = noTransform,
transformPlaceable = noTransform,
}: {
functions?: Record<string, FluentFunction>;
useIsolating?: boolean;
transform?: TextTransform;
transformPlaceable?: TextTransform;
} = {}
) {
this.locales = Array.isArray(locales) ? locales : [locales];
Expand All @@ -74,6 +81,7 @@ export class FluentBundle {
};
this._useIsolating = useIsolating;
this._transform = transform;
this._transformPlaceable = transformPlaceable;
this._intls = getMemoizerForLocale(locales);
}

Expand Down
6 changes: 4 additions & 2 deletions fluent-bundle/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function resolveVariableReference(
// Convert the argument to a Fluent type.
switch (typeof arg) {
case "string":
return arg;
return scope.bundle._transformPlaceable(arg);
case "number":
return new FluentNumber(arg);
case "object":
Expand Down Expand Up @@ -345,7 +345,9 @@ export function resolveComplexPattern(
result.push(FSI);
}

result.push(resolveExpression(scope, elem).toString(scope));
result.push(
resolveExpression(scope, elem).toString(scope)
);

if (useIsolating) {
result.push(PDI);
Expand Down