Skip to content

Commit

Permalink
Cleanup locize (#3)
Browse files Browse the repository at this point in the history
* Use locize.app instead of locize.io

* Remove addPath, no need to customize it

* Add snippet examples page

* Highlight /examples instead of /terms

* Update E2E tests to check for /examples instead of /terms

* Add E2E failed test with artifacts example
  • Loading branch information
Vadorequest authored Feb 28, 2020
1 parent 5f4b261 commit 3458fa3
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 25 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<a href="https://unly.org"><img src="https://storage.googleapis.com/unly/images/ICON_UNLY.png" align="right" height="20" alt="Unly logo" title="Unly logo" /></a>
[![Maintainability](https://api.codeclimate.com/v1/badges/3f3f2c0a4106abcb9a1d/maintainability)](https://codeclimate.com/github/UnlyEd/next-right-now/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/3f3f2c0a4106abcb9a1d/test_coverage)](https://codeclimate.com/github/UnlyEd/next-right-now/test_coverage)
[![Locize Latest version](https://img.shields.io/badge/dynamic/json.svg?style=plastic&color=2096F3&label=locize&query=%24.versions%5B%27latest%27%5D.translatedPercentage&url=https://api.locize.app/badgedata/658fc999-dfa8-4307-b9d7-b4870ad5b968&suffix=%+translated&link=https://www.locize.com&prefix=latest:+)](https://www.locize.io/p/w7jrmdie/statistics/badges)
[![Locize Production version](https://img.shields.io/badge/dynamic/json.svg?style=plastic&color=2096F3&label=locize&query=%24.versions%5B%27production%27%5D.translatedPercentage&url=https://api.locize.app/badgedata/658fc999-dfa8-4307-b9d7-b4870ad5b968&suffix=%+translated&link=https://www.locize.com&prefix=production:+)](https://www.locize.io/p/w7jrmdie/statistics/badges)
[![Locize Latest version](https://img.shields.io/badge/dynamic/json.svg?style=plastic&color=2096F3&label=locize&query=%24.versions%5B%27latest%27%5D.translatedPercentage&url=https://api.locize.app/badgedata/658fc999-dfa8-4307-b9d7-b4870ad5b968&suffix=%+translated&link=https://www.locize.com&prefix=latest:+)](https://www.locize.app/p/w7jrmdie/statistics/badges)
[![Locize Production version](https://img.shields.io/badge/dynamic/json.svg?style=plastic&color=2096F3&label=locize&query=%24.versions%5B%27production%27%5D.translatedPercentage&url=https://api.locize.app/badgedata/658fc999-dfa8-4307-b9d7-b4870ad5b968&suffix=%+translated&link=https://www.locize.com&prefix=production:+)](https://www.locize.app/p/w7jrmdie/statistics/badges)

Next Right Now
===
Expand Down Expand Up @@ -340,7 +340,7 @@ See the [official documentation](https://graphcms.com/docs/api/content-api/?ref=

> When the content we want to display doesn't come from GraphCMS API, then it's considered as a "static" content.
>
> This means that the content is managed by [Locize](https://www.locize.io/p/w7jrmdie/v/latest) and must be updated manually there.
> This means that the content is managed by [Locize](https://www.locize.app/p/w7jrmdie/v/latest) and must be updated manually there.
Check [this video](https://www.youtube.com/watch?v=9NOzJhgmyQE) to see Locize in action with react-i18next.

Expand All @@ -361,13 +361,13 @@ Once you're ready to ship the content to production, the `production` version ca
#### Locize additional services

Locize provides a few [additional services](https://www.locize.io/p/w7jrmdie/services). Some are free, some are paid.
Locize provides a few [additional services](https://www.locize.app/p/w7jrmdie/services). Some are free, some are paid.

#### Other additional services

- One interesting thing is the ability to share part of the project to be translated by a third party using [`Crowdbased`](https://www.locize.io/p/w7jrmdie/services), without sharing the whole project.
- There are also several paid [Translation services](https://www.locize.io/p/w7jrmdie/services), where you can pay people to translate your content.
- It is also possible to enable [Audit](https://www.locize.io/p/w7jrmdie/services), which allows to audit every change to our translations, and keep changes up to 10 years. (_expensive_)
- One interesting thing is the ability to share part of the project to be translated by a third party using [`Crowdbased`](https://www.locize.app/p/w7jrmdie/services), without sharing the whole project.
- There are also several paid [Translation services](https://www.locize.app/p/w7jrmdie/services), where you can pay people to translate your content.
- It is also possible to enable [Audit](https://www.locize.app/p/w7jrmdie/services), which allows to audit every change to our translations, and keep changes up to 10 years. (_expensive_)

---

Expand Down Expand Up @@ -438,7 +438,7 @@ Here is how the multiple steps are ordered:
1. A new Zeit deployment is triggered, which runs our tests first (`yarn test:once`) (Failing tests will stop the deployment)
1. Then, the deployment is deployed, and automatically linked to a custom domain which depends on the git branch name (xxx.now.sh)
1. Then, our 2E2 tests are triggered using Cypress
- If they fail, artifacts (screenshots, videos) recorded by Cypress are uploaded to Github to help further debug
- If they fail, artifacts (screenshots, videos) recorded by Cypress are uploaded to Github to help further debug (See [example](https://github.com/UnlyEd/next-right-now/runs/474607960))

## In-depth project's dependencies

Expand Down
6 changes: 3 additions & 3 deletions cypress/integration/app/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ describe('Index page', () => {
cy.get('#nav a.nav-link').should('have.length', 3);
});

it('should have a link in the navbar that redirects to the terms page', () => {
it('should have a link in the navbar that redirects to the examples page', () => {
cy.url().should('eq', `${baseUrl}/`);
cy.get('#nav-link-terms')
.should('have.text', 'Terms')
.should('have.text', 'Examples')
.click();
cy.url().should('eq', `${baseUrl}/terms`);
cy.url().should('eq', `${baseUrl}/examples`);
});
});
10 changes: 5 additions & 5 deletions src/components/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,18 @@ const Nav: React.FunctionComponent<Props> = (props: Props) => {

<NavItem>
<Link
href={`/terms`}
href={`/examples`}
>
<Col className={'navItemsMenu'}>
<Row className={'justify-content-center navItemsLogo'}>
<i className={classnames('fas fa-comments', { active: isActive(router, 'terms') })} />
<i className={classnames('fas fa-comments', { active: isActive(router, 'examples') })} />
</Row>
<Row className={'justify-content-center'}>
<NavLink
id={'nav-link-terms'}
active={isActive(router, 'terms')}
id={'nav-link-examples'}
active={isActive(router, 'examples')}
>
{t('nav.termsPage.link', 'CGU')}
{t('nav.examplesPage.link', 'Exemples')}
</NavLink>
</Row>
</Col>
Expand Down
147 changes: 147 additions & 0 deletions src/pages/examples.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/** @jsx jsx */
import { Amplitude, LogOnMount } from '@amplitude/react-amplitude';
import { css, jsx } from '@emotion/core';
import * as Sentry from '@sentry/node';
import { isBrowser } from '@unly/utils';
import { createLogger } from '@unly/utils-simple-logger';
import { NextPage } from 'next';
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars
import React from 'react';
import { Trans, useTranslation, UseTranslationResponse } from 'react-i18next';
import { Alert, Container } from 'reactstrap';
import uuid from 'uuid/v1';

import Head from '../components/Head';
import { PageProps } from '../types/PageProps';

const fileLabel = 'pages/examples';
const logger = createLogger({ // eslint-disable-line no-unused-vars,@typescript-eslint/no-unused-vars
label: fileLabel,
});

const Examples: NextPage<PageProps> = (props: PageProps): JSX.Element => {
const { t }: UseTranslationResponse = useTranslation();

Sentry.addBreadcrumb({ // See https://docs.sentry.io/enriching-error-data/breadcrumbs
category: fileLabel,
message: `Rendering examples page (${isBrowser() ? 'browser' : 'server'})`,
level: Sentry.Severity.Debug,
});

return (
<Amplitude
eventProperties={(inheritedProps): object => ({
...inheritedProps,
page: {
...inheritedProps.page,
name: 'examples',
},
})}
>
{({ logEvent }): JSX.Element => (
<>
<LogOnMount eventType="page-displayed" />
<Head />
<div
css={css`
justify-content: center;
text-align: center;
margin-left: auto;
margin-right: auto;
`}
>
<h1>Code snippet examples</h1>

<hr />

<h2>i18n examples</h2>
<Alert color={'info'}>
<div>
Each example shows the rendered version and its code snippet.<br />
The goal is to showcase real-world examples to help you get started faster and give a wider overview of what's possible.<br />
<a href={'https://react.i18next.com/'} target="blank" rel={'nofollow noreferrer'}>
Check the official documentation
</a>
</div>
</Alert>

<Container>
<div>
{t('examples.i18n.simpleTranslation', 'Traduction simple')}<br />
<code>{'{t(\'examples.i18n.simpleTranslation\', \'Traduction simple\')}'}</code>
</div>
<hr />

<div>
{t('examples.i18n.pluralTranslation', 'Traduction avec gestion du pluriel', { count: 1 })}<br />
<code>{'{t(\'examples.i18n.pluralTranslation\', \'Traduction avec gestion du pluriel\', { count: 1 })}'}</code>
</div>
<div>
{t('examples.i18n.pluralTranslation', 'Traduction avec gestion du pluriel', { count: 2 })}<br />
<code>{'{t(\'examples.i18n.pluralTranslation\', \'Traduction avec gestion du pluriel\', { count: 2 })}'}</code>
</div>
<hr />

<div>
<Trans
i18nKey={'examples.i18n.dynamicTranslation'}
>
Contenu dynamique : <b>{{ uuid: uuid() }}</b>
</Trans>
<br />
<code>
{'<Trans\n' +
' i18nKey="{\'examples.i18n.dynamicTranslation\'}"\n' +
'>\n' +
' Contenu dynamique : <b>{{ uuid: uuid() }}</b>\n' +
'</Trans>'}
</code>
</div>
<hr />

<div>
<Trans
i18nKey={'examples.i18n.dynamicPluralTranslation'}
count={1}
>
Nous avons trouvé {{ count: 1 }} solution pour vous.
</Trans>
<br />
<code>
{'<Trans\n' +
' i18nKey="{\'examples.i18n.dynamicPluralTranslation\'}"\n' +
' count="{1}"\n' +
'>\n' +
' Nous avons trouvé {{ count: 1 }} solution pour vous.\n' +
'</Trans>'}
</code>
</div>
<div>
<Trans
i18nKey={'examples.i18n.dynamicPluralTranslation'}
count={2}
>
Nous avons trouvé {{ count: 2 }} solution pour vous.
</Trans>
<br />
<code>
{'<Trans\n' +
' i18nKey="{\'examples.i18n.dynamicPluralTranslation\'}"\n' +
' count="{2}"\n' +
'>\n' +
' Nous avons trouvé {{ count: 2 }} solution pour vous.\n' +
'</Trans>'}
</code>
</div>
<hr />

</Container>
</div>
</>
)}
</Amplitude>
);

};

export default Examples;
6 changes: 1 addition & 5 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ const Home: NextPage<PageProps> = (props: PageProps): JSX.Element => {
margin-left: auto;
margin-right: auto;
a:hover{
text-decoration: none;
}
.product-container {
background-color: white;
border-radius: 10px;
Expand All @@ -131,7 +127,7 @@ const Home: NextPage<PageProps> = (props: PageProps): JSX.Element => {
<br />
We use a custom component <code>GraphCMSAsset</code> to display images.<br />
<br />
You can navigate between <Link href={'/terms'}>/terms</Link> and <Link href={'/'}>/</Link> to see CSR in action.<br />
You can navigate between <Link href={'/examples'}>/examples</Link> and <Link href={'/'}>/</Link> to see CSR in action.<br />
You can also disable JS on your browser to see how SSR works.<br />
<br />
You can also use
Expand Down
2 changes: 1 addition & 1 deletion src/pages/terms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Terms: NextPage<PageProps> = (props: PageProps): JSX.Element => {

Sentry.addBreadcrumb({ // See https://docs.sentry.io/enriching-error-data/breadcrumbs
category: fileLabel,
message: `Rendering index page (${isBrowser() ? 'browser' : 'server'})`,
message: `Rendering terms page (${isBrowser() ? 'browser' : 'server'})`,
level: Sentry.Severity.Debug,
});

Expand Down
5 changes: 2 additions & 3 deletions src/utils/i18nextLocize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ export const locizeBackendOptions = {
...locizeOptions,
// XXX "build" is meant to automatically invalidate the browser cache when releasing a different version,
// so that the end-users get the newest version immediately
loadPath: `https://api.locize.io/{{projectId}}/{{version}}/{{lng}}/{{ns}}?build=${process.env.BUILD_TIMESTAMP}`,
addPath: `https://api.locize.io/missing/{{projectId}}/{{version}}/{{lng}}/{{ns}}`,
loadPath: `https://api.locize.app/{{projectId}}/{{version}}/{{lng}}/{{ns}}?build=${process.env.BUILD_TIMESTAMP}`,
private: false, // Should never be private

/**
Expand Down Expand Up @@ -207,7 +206,7 @@ export const locizeBackendOptions = {
* - The browser's cache is completely disabled in development/staging, so that we may work/test with the latest translation
* See the official recommendations https://docs.locize.com/more/caching
* - Production stage:
* - When in production, the browser will also cache for 1h, because we configured a "Cache-control: Max-Age" at https://www.locize.io/p/w7jrmdie/settings
* - When in production, the browser will also cache for 1h, because we configured a "Cache-control: Max-Age" at https://www.locize.app/p/w7jrmdie/settings
* We followed the official recommendations https://docs.locize.com/more/caching
* 1h seems to be a good compromise between over-fetching (we don't expect our users to use the app for more than 1h straight)
* and applying translation "hot-fix" (worst case: "hot-fix"" be applied 1h later, which is acceptable)
Expand Down

0 comments on commit 3458fa3

Please sign in to comment.