Accent Documentation

repository·master·Indexed 23 days ago

https://github.com/mirego/accent

A developer-oriented translation tool providing an asynchronous workflow between translators and development teams. Accent includes a GraphQL API, a web UI, and a CLI (accent-cli) for managing app translations with full history and rollback capabilities. It supports synchronization, exporting, linting, and formatting of translation files, and can be deployed via Docker or installed for development using Elixir and Node.js.

Tokens
62.3K
Snippets
81
Records
339
Agent score
77%

What's inside Accent

  1. Configure document name patterns

    master

    The namePattern option in your files configuration determines how a file's name is represented in Accent. Available patterns:

    • file (default): Uses the filename without the extension. Example: Localizable.strings becomes Localizable.
    • fileWithSlugSuffix: Uses the filename without the extension and strips the language slug from the suffix. Example: Localizable.en.strings becomes Localizable.
    • parentDirectory: Uses the name of the directory containing the file. Useful when files are named only by language.
    • fileWithParentDirectory: Uses the file path in addition to the filename. The %slug% placeholder in the target path acts as the root for this path.
    {
      "files": [
        {
          "namePattern": "fileWithParentDirectory",
          "source": "translations/en/**/*.json",
          "target": "translations/%slug%/%document_path%.json"
        }
      ]
    }
  2. Understand the Project Lint Entry data flow

    master

    The data flow for managing lint entries follows this pattern:

    1. User Interaction: The FormModal manages local state and triggers an action (@onCreate, @onUpdate, or @onDelete) in the parent controller.
    2. Mutation: The controller uses apolloMutate.mutate to call the GraphQL mutation, passing the necessary variables and specifying refetchQueries: ['ProjectLintEntries'] to ensure the list stays in sync.
    3. Backend Processing: The Elixir backend processes the mutation. If the changeset is invalid, it returns successful: false and a list of error messages.
    4. UI Update: Upon a successful mutation, the ProjectLintEntries query is refetched, the list re-renders, and a success flash message is displayed. If errors occur, the modal remains open and error messages are displayed.
  3. Extract version from Git branches

    master

    Accent can automatically extract a version from your current Git branch name using the branchVersionPrefix setting in the version object.

    If you set "branchVersionPrefix": "release/", a branch named release/v1.0.0 will cause the sync and stats commands to behave as if --version=1.0.0 was passed.

    "version": {
      "branchVersionPrefix": "release/"
    }
  4. Use lifecycle hooks in Accent configuration

    master

    You can define shell commands to run at specific points in the Accent CLI lifecycle using the hooks key in your file configuration. Available hooks are:

    • beforeSync
    • afterSync
    • beforeExport
    • afterExport
    "hooks": {
      "afterSync": ["touch sync-done.txt", "echo 'Done!'"]
    }
  5. Run Accent locally with Docker Compose

    master

    You can run a production-like environment locally using Docker and docker-compose without installing Elixir or NodeJS. This uses an OTP release of the app.

    1. Build the OTP release: make build
    2. Start PostgreSQL: make dev-start-postgresql (runs on port 5432 with user postgres).
    3. Start the application: make dev-start-application. The release hook will automatically execute migrations and seeds before starting the webserver on port 4000.
  6. Update file configuration for version 0.8.0+

    master
    Starting with version 0.8.0, the language key is no longer supported within individual items in the files configuration. The language is now always treated as the master language for the operation.
  7. Configure the Accent CLI with accent.json

    master

    The Accent CLI uses an accent.json file for project configuration. This file defines your connection to the Accent instance and how files are mapped between your local filesystem and the server.

    Global Configuration Keys

    • apiUrl: The base URL of your Accent Instance.
    • apiKey: API Key for your Accent Instance.
    • project: Your Project UUID.

    Environment Variable Overrides

    You can override accent.json values by setting the following environment variables:

    • ACCENT_API_KEY (Overrides apiKey)
    • ACCENT_API_URL (Overrides apiUrl)
    • ACCENT_PROJECT (Overrides project)

    File Mapping Configuration

    Within the files array, you can define how specific files are handled:

    • language: The identifier of the document's language.
    • format: The document format (e.g., json, strings).
    • source: Path to the document (supports glob patterns).
    • target: Path for target languages (supports %slug% and %document_path% placeholders).
    • namePattern: Strategy for naming the document in Accent.
    • hooks: List of lifecycle hooks to execute.
    {
      "apiUrl": "http://your.accent.instance",
      "apiKey": "2nziVSaa8yUJxLkwoZA",
      "version": {
        "branchVersionPrefix": "release/"
      },
      "files": [
        {
          "format": "json",
          "source": "localization/fr/*.json",
          "target": "localization/%slug%/%document_path%.json",
          "hooks": {
            "afterSync": ["touch sync-done.txt", "echo 'Done!'"]
          }
        }
      ]
    }
  8. Verify Lint Entry changes with backend and frontend tests

    master

    To verify changes to the Project Lint Entry management system, run the following commands:

    Backend (Elixir):

    mix format
    mix credo --strict
    mix compile --warnings-as-errors --force
    env $(cat .env.test.local | xargs) mix test test/graphql/resolvers/lint_test.exs

    Frontend (Ember/TypeScript):

    cd webapp
    node node_modules/.bin/tsc        # type-check
    node node_modules/.bin/ember build --output-path=<tmp>   # template/component compile
  9. Contribute to Accent

    master

    When contributing to the project, follow these steps:

    1. Open an issue before opening a pull request.
    2. Ensure your additions pass the test suite.
    3. Run the ./priv/scripts/ci-check.sh script locally to verify that the CI build will pass before submitting your PR.