ab-translate
Quickly create AB Tests for texts without coding via Wix Babel & Guineapig.
The prcess requries two simple steps:
- Setup - one time config for a project to support the AB Translate flow
- Test - create as many tests as you or you Product Manager wishes
Setup
Do this once, for each project that you want to run translations tests in
Yoshi (new stack)
- Install the package
npm i ab-translate --save
or yarn add ab-translate
- Configure the specs defaults in your
package.json
file (example):
"yoshi": {
"petriSpecs": {
onlyForLoggedInUsers: false,
scopes: ['my-projects-translation-scope']
}
}
- Save the petri experiments object to the window (e.g.
window.__EXPERIMENTS__ = '<%= experiments %>';
). Notice: make sure that you conduct the experiments for the scope in step #2 - In the
src/i18n.js
file add the following code to the backend task (example)
import abTranslate from ‘ab-translate/dist/src/abTranslate-runtime’;
backend: {
crossDomain: true,
parse: translations => {
try {
return abTranslate(window.__EXPERIMENTS__, JSON.parse(translations));
} catch (e) {
return translations;
}
}
}
Wix Grunt (old stack)
- Install the package
npm i ab-translate --save
- Configure the specs defaults in your local
Gruntfile.js
file:
grunt.modifyTask('petriExperiments', {
options: {
onlyForLoggedInUsers: false,
scopes: ['my-projects-translation-scope']
}
});
- Add the Angular
abTranslateProvider
to your index.vm
file (example)
<script src="bower_components/ab-translate.git/abTranslate.angular-runtime.bundle.min.js"></script>
- Transform the translations using the
abTranslateProvider
and the project's experimentManagerProvider
(example). Notice: make sure that you conduct the experiments for the scope in step #2
angular.module('myApp', [])
.config(function($translateProvider, abTranslateProvider, experimentManagerProvider) {
const preferredLanguage = $translateProvider.preferredLanguage();
const translations = $translateProvider.translations()[preferredLanguage];
const translationsWithExperiments = abTranslateProvider.abTranslate.default(
experimentManagerProvider.experiments,
translations
);
$translateProvider.translations(preferredLanguage, translationsWithExperiments);
});
Test