coralproject / talk

A better commenting experience from Vox Media
https://coralproject.net
Other
1.89k stars 354 forks source link

Make default language an optional ENV variable #1041

Closed kgardnr closed 7 years ago

kgardnr commented 7 years ago

AC:

wyattjoh commented 7 years ago

Load the language into the client via https://github.com/coralproject/talk/blob/ff9ae035224865ee2ed5ae30100a5632fd9d41e2/routes/static.js#L1-L13

And load it with https://github.com/coralproject/talk/blob/ab1f1dee3e1110e276724c103bf681054b78b7e2/client/coral-framework/services/bootstrap.js#L105

PepeFranco commented 7 years ago

If no one is working on this yet I would like do so

kgardnr commented 7 years ago

Welcome @PepeFranco! Thank you - it's all yours! :)

PepeFranco commented 7 years ago

Hey @wyattjoh ,

I have some doubts regarding this. I'm just getting familiarized with the code. I understand I need to initialize a variable on config that pulls from env variables. I can then export it on routes/static.js and load it to bootstrap via getStaticConfiguration method.

If I'm not mistaken the i18n.js file which manages translations sets a default locale from either local storage, navigator or defaults to english when it is first required. It makes sense to me then that on the initialization it should pull the environment variable (if any) and default to that. To do so can I refer to it simply by process.env or should I import the getStaticConfiguration method from the bootstrap file to properly get this variable?

Or is there a way to pass the default variable loaded on bootstrap to the i18n file, say from local storage or the redux store?

Let me know if this makes sense or if I should clarify something.

wyattjoh commented 7 years ago

Hey @PepeFranco.

After further reviewing, I think it may be best to expose it at build time.

Checkout https://github.com/coralproject/talk/blob/1ba5fd0028517b4ec9b3e75b4371f7506082edd3/webpack.config.js#L111-L114 and add the TALK_DEFAULT_LANG variable, and replace https://github.com/coralproject/talk/blob/197d94ffb1978d038a641996ef1a9146c2f32133/client/coral-framework/services/i18n.js#L16 with process.env.TALK_DEFAULT_LANG.

For extra points, document the new variable in our docs. Checkout our docs and add the new variable under the advanced configuration page. If you have questions, feel free to ping me again here :smile:

kgardnr commented 7 years ago

Fixed in #1053

larrylizhao commented 6 years ago

Hi @wyattjoh I'm a developer from WSJ and we are developing the CN version of WSJ. So I'm following the instructions in the doc to get talk in Chinese, but after the image built and run, it's still in English. My Dockerfile is as follows:

FROM coralproject/talk:4.3.2

COPY . /usr/src/app ENV TALK_DISABLE_EMBED_POLYFILL TRUE ARG TALK_DEFAULT_LANG=zh_CN # Also tried # ENV TALK_DEFAULT_LANG=zh_CN

RUN yarn config set registry http://production.npmserver.virginia.onservo.com && \ cli plugins reconcile && \ yarn && \ yarn build && \ yarn cache clean

CMD ["./bin/cli-serve", "-j", "-w", "--disabled-jobs", "mailer"]

Am I doing something wrong or missing something? Many thanks!

wyattjoh commented 6 years ago

It may be the case that your web browser is still sending the wrong language to Talk, as it will try to get the browsers current language when you load the page.