Skip to content

Commit 3458fa3

Browse files
authored
Cleanup locize (#3)
* 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
1 parent 5f4b261 commit 3458fa3

File tree

7 files changed

+167
-25
lines changed

7 files changed

+167
-25
lines changed

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<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>
22
[![Maintainability](https://api.codeclimate.com/v1/badges/3f3f2c0a4106abcb9a1d/maintainability)](https://codeclimate.com/github/UnlyEd/next-right-now/maintainability)
33
[![Test Coverage](https://api.codeclimate.com/v1/badges/3f3f2c0a4106abcb9a1d/test_coverage)](https://codeclimate.com/github/UnlyEd/next-right-now/test_coverage)
4-
[![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)
5-
[![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)
4+
[![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)
5+
[![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)
66

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

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

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

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

366366
#### Other additional services
367367

368-
- 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.
369-
- There are also several paid [Translation services](https://www.locize.io/p/w7jrmdie/services), where you can pay people to translate your content.
370-
- 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_)
368+
- 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.
369+
- There are also several paid [Translation services](https://www.locize.app/p/w7jrmdie/services), where you can pay people to translate your content.
370+
- 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_)
371371

372372
---
373373

@@ -438,7 +438,7 @@ Here is how the multiple steps are ordered:
438438
1. A new Zeit deployment is triggered, which runs our tests first (`yarn test:once`) (Failing tests will stop the deployment)
439439
1. Then, the deployment is deployed, and automatically linked to a custom domain which depends on the git branch name (xxx.now.sh)
440440
1. Then, our 2E2 tests are triggered using Cypress
441-
- If they fail, artifacts (screenshots, videos) recorded by Cypress are uploaded to Github to help further debug
441+
- 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))
442442

443443
## In-depth project's dependencies
444444

cypress/integration/app/pages/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ describe('Index page', () => {
2626
cy.get('#nav a.nav-link').should('have.length', 3);
2727
});
2828

29-
it('should have a link in the navbar that redirects to the terms page', () => {
29+
it('should have a link in the navbar that redirects to the examples page', () => {
3030
cy.url().should('eq', `${baseUrl}/`);
3131
cy.get('#nav-link-terms')
32-
.should('have.text', 'Terms')
32+
.should('have.text', 'Examples')
3333
.click();
34-
cy.url().should('eq', `${baseUrl}/terms`);
34+
cy.url().should('eq', `${baseUrl}/examples`);
3535
});
3636
});

src/components/Nav.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -196,18 +196,18 @@ const Nav: React.FunctionComponent<Props> = (props: Props) => {
196196

197197
<NavItem>
198198
<Link
199-
href={`/terms`}
199+
href={`/examples`}
200200
>
201201
<Col className={'navItemsMenu'}>
202202
<Row className={'justify-content-center navItemsLogo'}>
203-
<i className={classnames('fas fa-comments', { active: isActive(router, 'terms') })} />
203+
<i className={classnames('fas fa-comments', { active: isActive(router, 'examples') })} />
204204
</Row>
205205
<Row className={'justify-content-center'}>
206206
<NavLink
207-
id={'nav-link-terms'}
208-
active={isActive(router, 'terms')}
207+
id={'nav-link-examples'}
208+
active={isActive(router, 'examples')}
209209
>
210-
{t('nav.termsPage.link', 'CGU')}
210+
{t('nav.examplesPage.link', 'Exemples')}
211211
</NavLink>
212212
</Row>
213213
</Col>

src/pages/examples.tsx

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/** @jsx jsx */
2+
import { Amplitude, LogOnMount } from '@amplitude/react-amplitude';
3+
import { css, jsx } from '@emotion/core';
4+
import * as Sentry from '@sentry/node';
5+
import { isBrowser } from '@unly/utils';
6+
import { createLogger } from '@unly/utils-simple-logger';
7+
import { NextPage } from 'next';
8+
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars
9+
import React from 'react';
10+
import { Trans, useTranslation, UseTranslationResponse } from 'react-i18next';
11+
import { Alert, Container } from 'reactstrap';
12+
import uuid from 'uuid/v1';
13+
14+
import Head from '../components/Head';
15+
import { PageProps } from '../types/PageProps';
16+
17+
const fileLabel = 'pages/examples';
18+
const logger = createLogger({ // eslint-disable-line no-unused-vars,@typescript-eslint/no-unused-vars
19+
label: fileLabel,
20+
});
21+
22+
const Examples: NextPage<PageProps> = (props: PageProps): JSX.Element => {
23+
const { t }: UseTranslationResponse = useTranslation();
24+
25+
Sentry.addBreadcrumb({ // See https://docs.sentry.io/enriching-error-data/breadcrumbs
26+
category: fileLabel,
27+
message: `Rendering examples page (${isBrowser() ? 'browser' : 'server'})`,
28+
level: Sentry.Severity.Debug,
29+
});
30+
31+
return (
32+
<Amplitude
33+
eventProperties={(inheritedProps): object => ({
34+
...inheritedProps,
35+
page: {
36+
...inheritedProps.page,
37+
name: 'examples',
38+
},
39+
})}
40+
>
41+
{({ logEvent }): JSX.Element => (
42+
<>
43+
<LogOnMount eventType="page-displayed" />
44+
<Head />
45+
<div
46+
css={css`
47+
justify-content: center;
48+
text-align: center;
49+
margin-left: auto;
50+
margin-right: auto;
51+
`}
52+
>
53+
<h1>Code snippet examples</h1>
54+
55+
<hr />
56+
57+
<h2>i18n examples</h2>
58+
<Alert color={'info'}>
59+
<div>
60+
Each example shows the rendered version and its code snippet.<br />
61+
The goal is to showcase real-world examples to help you get started faster and give a wider overview of what's possible.<br />
62+
<a href={'https://react.i18next.com/'} target="blank" rel={'nofollow noreferrer'}>
63+
Check the official documentation
64+
</a>
65+
</div>
66+
</Alert>
67+
68+
<Container>
69+
<div>
70+
{t('examples.i18n.simpleTranslation', 'Traduction simple')}<br />
71+
<code>{'{t(\'examples.i18n.simpleTranslation\', \'Traduction simple\')}'}</code>
72+
</div>
73+
<hr />
74+
75+
<div>
76+
{t('examples.i18n.pluralTranslation', 'Traduction avec gestion du pluriel', { count: 1 })}<br />
77+
<code>{'{t(\'examples.i18n.pluralTranslation\', \'Traduction avec gestion du pluriel\', { count: 1 })}'}</code>
78+
</div>
79+
<div>
80+
{t('examples.i18n.pluralTranslation', 'Traduction avec gestion du pluriel', { count: 2 })}<br />
81+
<code>{'{t(\'examples.i18n.pluralTranslation\', \'Traduction avec gestion du pluriel\', { count: 2 })}'}</code>
82+
</div>
83+
<hr />
84+
85+
<div>
86+
<Trans
87+
i18nKey={'examples.i18n.dynamicTranslation'}
88+
>
89+
Contenu dynamique : <b>{{ uuid: uuid() }}</b>
90+
</Trans>
91+
<br />
92+
<code>
93+
{'<Trans\n' +
94+
' i18nKey="{\'examples.i18n.dynamicTranslation\'}"\n' +
95+
'>\n' +
96+
' Contenu dynamique : <b>{{ uuid: uuid() }}</b>\n' +
97+
'</Trans>'}
98+
</code>
99+
</div>
100+
<hr />
101+
102+
<div>
103+
<Trans
104+
i18nKey={'examples.i18n.dynamicPluralTranslation'}
105+
count={1}
106+
>
107+
Nous avons trouvé {{ count: 1 }} solution pour vous.
108+
</Trans>
109+
<br />
110+
<code>
111+
{'<Trans\n' +
112+
' i18nKey="{\'examples.i18n.dynamicPluralTranslation\'}"\n' +
113+
' count="{1}"\n' +
114+
'>\n' +
115+
' Nous avons trouvé {{ count: 1 }} solution pour vous.\n' +
116+
'</Trans>'}
117+
</code>
118+
</div>
119+
<div>
120+
<Trans
121+
i18nKey={'examples.i18n.dynamicPluralTranslation'}
122+
count={2}
123+
>
124+
Nous avons trouvé {{ count: 2 }} solution pour vous.
125+
</Trans>
126+
<br />
127+
<code>
128+
{'<Trans\n' +
129+
' i18nKey="{\'examples.i18n.dynamicPluralTranslation\'}"\n' +
130+
' count="{2}"\n' +
131+
'>\n' +
132+
' Nous avons trouvé {{ count: 2 }} solution pour vous.\n' +
133+
'</Trans>'}
134+
</code>
135+
</div>
136+
<hr />
137+
138+
</Container>
139+
</div>
140+
</>
141+
)}
142+
</Amplitude>
143+
);
144+
145+
};
146+
147+
export default Examples;

src/pages/index.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ const Home: NextPage<PageProps> = (props: PageProps): JSX.Element => {
104104
margin-left: auto;
105105
margin-right: auto;
106106
107-
a:hover{
108-
text-decoration: none;
109-
}
110-
111107
.product-container {
112108
background-color: white;
113109
border-radius: 10px;
@@ -131,7 +127,7 @@ const Home: NextPage<PageProps> = (props: PageProps): JSX.Element => {
131127
<br />
132128
We use a custom component <code>GraphCMSAsset</code> to display images.<br />
133129
<br />
134-
You can navigate between <Link href={'/terms'}>/terms</Link> and <Link href={'/'}>/</Link> to see CSR in action.<br />
130+
You can navigate between <Link href={'/examples'}>/examples</Link> and <Link href={'/'}>/</Link> to see CSR in action.<br />
135131
You can also disable JS on your browser to see how SSR works.<br />
136132
<br />
137133
You can also use

src/pages/terms.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const Terms: NextPage<PageProps> = (props: PageProps): JSX.Element => {
3737

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

src/utils/i18nextLocize.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ export const locizeBackendOptions = {
154154
...locizeOptions,
155155
// XXX "build" is meant to automatically invalidate the browser cache when releasing a different version,
156156
// so that the end-users get the newest version immediately
157-
loadPath: `https://api.locize.io/{{projectId}}/{{version}}/{{lng}}/{{ns}}?build=${process.env.BUILD_TIMESTAMP}`,
158-
addPath: `https://api.locize.io/missing/{{projectId}}/{{version}}/{{lng}}/{{ns}}`,
157+
loadPath: `https://api.locize.app/{{projectId}}/{{version}}/{{lng}}/{{ns}}?build=${process.env.BUILD_TIMESTAMP}`,
159158
private: false, // Should never be private
160159

161160
/**
@@ -207,7 +206,7 @@ export const locizeBackendOptions = {
207206
* - The browser's cache is completely disabled in development/staging, so that we may work/test with the latest translation
208207
* See the official recommendations https://docs.locize.com/more/caching
209208
* - Production stage:
210-
* - 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
209+
* - 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
211210
* We followed the official recommendations https://docs.locize.com/more/caching
212211
* 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)
213212
* and applying translation "hot-fix" (worst case: "hot-fix"" be applied 1h later, which is acceptable)

0 commit comments

Comments
 (0)