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

Add setLocale method #140

Merged
merged 4 commits into from
Nov 3, 2021
Merged
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
1 change: 1 addition & 0 deletions dist/leanplum.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default class Leanplum {
static setAppIdForProductionMode(appId: string, accessKey: string): void;
static setSocketHost(host: string): void;
static setDeviceId(deviceId: string): void;
static setLocale(locale: string): void;
static setAppVersion(versionName: string): void;
static setDeviceName(deviceName: string): void;
static setDeviceModel(deviceModel: string): void;
Expand Down
4 changes: 4 additions & 0 deletions src/Leanplum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export default class Leanplum {
Leanplum._lp.setDeviceId(deviceId)
}

static setLocale(locale: string): void {
Leanplum._lp.setLocale(locale)
}

static setAppVersion(versionName: string): void {
Leanplum._lp.setAppVersion(versionName)
}
Expand Down
7 changes: 6 additions & 1 deletion src/LeanplumInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default class LeanplumInternal {

private _deviceName: string
private _deviceModel: string
private _locale: string
private _systemName: string
private _systemVersion: string
private _sessionLength: number
Expand Down Expand Up @@ -123,6 +124,10 @@ export default class LeanplumInternal {
this._lpRequest.deviceId = deviceId
}

setLocale(locale: string): void {
this._locale = locale
}

setAppVersion(versionName: string): void {
this._lpRequest.versionName = versionName
}
Expand Down Expand Up @@ -294,7 +299,7 @@ export default class LeanplumInternal {
.add(Constants.PARAMS.SYSTEM_VERSION, (this._systemVersion || '').toString())
.add(Constants.PARAMS.BROWSER_NAME, this._browserDetector.browser)
.add(Constants.PARAMS.BROWSER_VERSION, this._browserDetector.version.toString())
.add(Constants.PARAMS.LOCALE, Constants.VALUES.DETECT)
.add(Constants.PARAMS.LOCALE, this._locale || Constants.VALUES.DETECT)
.add(Constants.PARAMS.DEVICE_NAME, this._deviceName ||
`${this._browserDetector.browser} ${this._browserDetector.version}`)
.add(Constants.PARAMS.DEVICE_MODEL, this._deviceModel || 'Web Browser')
Expand Down
29 changes: 29 additions & 0 deletions test/specs/LeanplumInternal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,35 @@ describe(LeanplumInternal, () => {
expect(newsfeedMessages).toEqual(['123##1', '234##1'])
})

it('sends detect locale by default', () => {
mockNextResponse({
response: [{
success: true,
}],
})
lp.start()

const [method, args] = lpRequestMock.request.mock.calls[0]
const { locale } = args.buildDict()
expect(method).toBe('start')
expect(locale).toEqual('(detect)')
})

it('sends defined locale', () => {
mockNextResponse({
response: [{
success: true,
}],
})
lp.setLocale('it_CH')
lp.start()

const [method, args] = lpRequestMock.request.mock.calls[0]
const { locale } = args.buildDict()
expect(method).toBe('start')
expect(locale).toEqual('it_CH')
})

it('synchronizes message inbox, if requested by API', () => {
mockNextResponse({
response: [{
Expand Down