# ab-translate-old

> Quickly create AB Tests for texts without coding via [Wix Babel](https://bo.wix.com/wix-babel-webapp/babel) & [Guineapig](https://guineapig.wix.com/home).

Latest version **1.1.0** (published 2017-10-27) · 0 weekly downloads

## Install

```sh
npm install ab-translate-old
pnpm add ab-translate-old
yarn add ab-translate-old
bun add ab-translate-old
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2017-10-27 |
| First published | 2017-10-27 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| Author | Yair Haimovitch |
| Maintainers | wix-ci |

## Links

- npm: https://www.npmjs.com/package/ab-translate-old
- npm.io page: https://npm.io/package/ab-translate-old

## Dependencies (4)

- [fs](https://npm.io/package/fs.md) 0.0.1-security
- [glob](https://npm.io/package/glob.md) ^7.1.2
- [xml2js](https://npm.io/package/xml2js.md) ^0.4.19
- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.22.0

## Recent versions

- 1.1.0 (latest) — 2017-10-27

## README

# ab-translate
Quickly create AB Tests for texts without coding via [Wix Babel](https://bo.wix.com/wix-babel-webapp/babel) & [Guineapig](https://guineapig.wix.com/home).

The process requries two simple steps:
1. [**Setup**](#setup) - one time config for a project to support the AB Translate flow
2. [**AB Test**](#ab-test) - create as many text tests as you or your Writer needs without writing a single line of code!!!!1 😱

## Setup
Do this once, for each project that you want to run translations tests in

### Yoshi (new stack)
1. Install the package `npm i ab-translate --save` or `yarn add ab-translate`
2. Configure the specs defaults in your `package.json` file ([example](https://github.com/wix-private/account-recovery/blob/master/package.json#L15)):
```javascript
"yoshi": {
  "petriSpecs": {
    onlyForLoggedInUsers: false, // default: true
    scopes: ['my-projects-translation-scope'] // default: [<artifactId>]
  }
}
```
3. 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
4. In the `src/i18n.js` file add the following code to the backend task ([example](https://github.com/wix-private/account-recovery/blob/master/src/i18n/client-i18n.js#L22))
```javascript
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)
1. Install the package `npm i ab-translate --save`
2. Configure the specs defaults in your local `Gruntfile.js` file:
```javascript
grunt.modifyTask('petriExperiments', {
  options: {
    onlyForLoggedInUsers: false, // default: true
    scopes: ['my-projects-translation-scope'] // default: [<artifactId>]
  }
});
```
3. Add the Angular `abTranslateProvider` to your `index.vm` file ([example](https://github.com/wix-private/site-generator-statics-consumer/blob/00f9120d1964725aa3a89217f48978264210caa2/app/index.vm#L189))
```html
<script src="bower_components/ab-translate.git/abTranslate.angular-runtime.bundle.min.js"></script>
```
4. Transform the translations using the `abTranslateProvider` and the project's `experimentManagerProvider` ([example](https://github.com/wix-private/site-generator-statics-consumer/blob/15d0f98603a575b5eda742ede781cf63f791f04b/app/scripts/app.ts#L80)). *Notice:* make sure that you conduct the experiments for the scope in step #2
```javascript
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);
  });
```

## AB Test

1. Go to the [Babel translation system](https://bo.wix.com/wix-babel-webapp/babel)
2. Select your project in the `Current Project` dropdown and select the `Update` tab
![Babel Home](docs/1.babel.home.png)
3. Look for the translation key you want to create a test for and click on the `Edit` button
![Update key](docs/2.update.keys.png)
4. Click on the `Create AB Test` button at the bottom of the modal
![Create AB Test](docs/3.babel.edit.png)
5. Add as many alternatives as you want
![Add Alternatives](docs/4.babel.add.variations.png)
6. Click the `Set` button. A 🔀 sign should appear next to your key.
7. Verify your changes and click the `Commit` button.
![Commit Changes](docs/5.babel.commit.changes.png)
8. The changes will be pushed to github and a new build will be triggered. The new AB test will be detected and will be created.
9. In the **Next GA** of the project you'll be able to see the spec in [Guineapig](https://guineapig.wix.com/home). The spec name will be in the format `specs.abTranslate.<scope>.<key>`.
10. Create an experiment and use [Petri Sidekick](https://chrome.google.com/webstore/detail/wix-petri-sidekick/hpdjckcenihbjfmaccadiaighajcjope) to verify the variations!

**Note1:** When creating the experiment verify that you open it only for the languages where the keys were updated
**Note2:** If the experiment is paused/killed/theres a bug in the system the first alternative (String #0) will be chosen so there shouldn't be any risks with this mechanism.

### Merging an Experiment
Unfurtunately, at the moment there's no `Quick Merge` button that allows you to select the winning text. We'll work on one once the demand will rise. In the mean time you can simply set all the alternatives to the same text, close the experiments, and finally ask your dev to remove the unnecessary keys.

### Experiments in languages other than EN
Creating an experiment in other languages is possible, however there's a few things you should keep in mind:
1. Make sure that all variations are translated otherwise you'll have some variations fallback to English
2. When you merge a multi-lingual experiment the winner for each language might be different (in some languages A may win, while in other languages B, or C, etc). Keep that in mind when you get to that point. We hope to make your life easier with an auto-merge flow in the future :)

## Credits
* Guild Week Stars ✨
  * [@GuySopher](https://github.com/guysopher)
  * [@Yairhaimo](https://github.com/yairhaimo)
* FED Infra Team

---
_Source: https://npm.io/package/ab-translate-old · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
