How to use the @airbnb/lunar/lib/components/Translate.phrase function in @airbnb/lunar

To help you get started, we’ve selected a few @airbnb/lunar examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github airbnb / lunar / packages / forms / src / components / FeedbackForm / index.tsx View on Github external
validate(value: string) {
    if (!value) {
      throw new Error(
        T.phrase(
          'This field is required.',
          {},
          {
            context: 'Generic error when a form field is required',
            key: 'lunar.form.fieldRequired',
          },
        ),
      );
    }
  }
github airbnb / lunar / packages / forms / src / components / FeedbackForm / index.tsx View on Github external
))}
        

        <textarea k="lunar.feedback.moreMessage" label="{" name="feedback">          }
          placeholder={
            data.type === 'bug'
              ? T.phrase(
                  'What happened? Sharing steps to reproduce the problem you experienced can be helpful.',
                  {},
                  {
                    context:
                      'Default description in the feedback form when submitting a bug report',
                    key: 'lunar.feedback.moreBug',
                  },
                )
              : T.phrase(
                  'Share your experience with us. What went well? What could have gone better?',
                  {},
                  {
                    context:
                      'Default description in the feedback form when submitting general feedback',
                    key: 'lunar.feedback.moreFeedback',
                  },</textarea>
github airbnb / lunar / packages / forms / src / components / Form / index.tsx View on Github external
private handleValidate = throttleToSinglePromise(async (data: object) => {
    const nextData = data as Data;
    const errors = await this.validate(nextData);
    const passes = this.props.onValidate!(nextData, errors, this.getFields());
    let errorCount = Object.keys(errors).length;

    if (!passes && errorCount === 0) {
      errors[FORM_ERROR] = T.phrase(
        'Failed to validate form. Please try again.',
        {},
        {
          context: 'A generic error when a form failed validation in any way',
          key: 'lunar.form.validateFailed',
        },
      );
      errorCount += 1;
    }

    if (errorCount > 0) {
      this.props.onFailedValidate!(nextData, errors);
    }

    return errors;
  });
github airbnb / lunar / packages / forms / src / components / Form / index.tsx View on Github external
return promise.catch(error => {
      if (setErrors) {
        setErrors({
          [FORM_ERROR]: T.phrase(
            'Failed to submit form. %{error}',
            {
              error: getErrorMessage(error),
            },
            {
              context: 'A generic error when a form failed to submit',
              key: 'lunar.form.submitFailed',
            },
          ),
        });
      }

      this.props.onFailedSubmit!(preparedData, error);

      throw error;
    });
github airbnb / lunar / packages / forms / src / components / FeedbackForm / index.tsx View on Github external
phrase="Tell us a little bit more"
              context="Feedback form"
            /&gt;
          }
          placeholder={
            data.type === 'bug'
              ? T.phrase(
                  'What happened? Sharing steps to reproduce the problem you experienced can be helpful.',
                  {},
                  {
                    context:
                      'Default description in the feedback form when submitting a bug report',
                    key: 'lunar.feedback.moreBug',
                  },
                )
              : T.phrase(
                  'Share your experience with us. What went well? What could have gone better?',
                  {},
                  {
                    context:
                      'Default description in the feedback form when submitting general feedback',
                    key: 'lunar.feedback.moreFeedback',
                  },
                )
          }
          validator={this.validate}
        /&gt;
github airbnb / lunar / packages / forms / src / components / FeedbackForm / index.tsx View on Github external
/&gt;
              
            )}
          
        )}

        <select k="lunar.feedback.featureMessage" label="{" name="category">
          }
          placeholder={T.phrase(
            'Select a feature',
            {},
            {
              context: 'Selecting a feature within the feedback form',
              key: 'lunar.feedback.selectFeature',
            },
          )}
          validator={this.validate}
        &gt;
          {Object.entries(categories).map(([key, label]) =&gt; (
            <option value="{key}">
              {label}
            </option>
          ))}
        </select>