Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Name according to language

Started by Muut Archive 11 years ago · 18 replies · 623 views
11 years ago

in multilanguage section of learn.getgrav, ther an example with the month of the year:

YAML
en:
  MONTHS_OF_THE_YEAR: [January, February, March, April, May, June, July, August, September, October, November, December]

Could you precise in which document is it extract from?
(I guess it is probably a yaml file but it can't find out which one

I have a problem with variables according to languages:

For instance, I would like the japanese blog section to have date in japanese:

  1. I have looked at the template and see perfectly that ther is a variable d for day and another M for month (code: see below) but I can't find out how to.
    ---html
    <span>{{ page.date|date("d") }}</span>
    <em>{{ page.date|date("M") }}</em>

    TXT
    
    
  2. I precised that I have made all the changes possible in system/languages/ with fr.yaml or ja.yaml (created for the purpose) and also in user/languages/ with the same fr.yaml or ja.yaml, without result.

here the file's redaction of fr.yamlfor checking:
folowing exem ple of multilanguage section of learn.getgrav:
MONTHS_OF_THE_YEAR: [Janvier, Fevrier, Mars, Avril, Mai, Juin, Juillet, Août, Septembre, Octobre, Novembre, Decembre],
exactly same redaction as the standart system Grav file plus the previous line repeated at 2 differents indention level:

  • first one at same level of indention than other date variable,
  • second on the above primary level.
    That's gives this:
    YAML
    
    DEC_PLURAL: d
    MONTHS_OF_THE_YEAR: [Janvier, Fevrier, Mars, Avril, Mai, Juin, Juillet, Août, Septembre, Octobre, Novembre, Decembre]
    MONTHS_OF_THE_YEAR: [Janvier, Fevrier, Mars, Avril, Mai, Juin, Juillet, Août, Septembre, Octobre, Novembre, Decembre]
    ---
    
11 years ago

I have the same problem for display my name correctly in each language.

I have first wrote in user/config/site.yaml

YAML
name:
   -fr: 'François Vidit'
   - ja: 'Francois Vidit (フランソワ・ヴィディ)'
   - en: 'Francois Vidit'

on the model given in leanr.getgrav.org

but

it's provocating an error with the feed atom plugin that cannot handle these definitions.

Thank you in advance for your help

11 years ago

That on the Learn site is just an example.

'd' and 'M' are PHP date formats, used to print the day or the month, nothing to do with the translations.

The theme is not configured to translate the dates, so you can just edit {{ page.date|date("M") }} to {{ page.date|date("M")|t }} (notice |t which means "translate") and add to your language file

Jan: month-name-in-japanese
Feb: month-name-in-japanese

Do not add them under system/languages/ but under user/languages/

11 years ago

I am sorry, I cannot manage to get to the any of the 2 points (fr and ja):

here are the two lines the way they are now:
---html
<span class="list-blog-date">
<span>{{ page.date|date("d")|t }}</span>
<em>{{ page.date|date("M")|t }}</em>
</span>

TXT


then, in `user/languages` changes were made for `fr.yaml` this way:
(I started by french because it is originally set in Grav therefore easier).
*1* (recommanded way)
`Jan: Jan`
`Feb: Fév`
etc ...
no result

*2* (as other variables are set that way)
`JAN: 'Jan'`
`FEV: 'Fév'`
etc ... 
no result

*3* (as other variables are set that way)
`'Jan': 'Jan'`
`'Feb': 'Fév'`
etc ...
no result

*4* (try, as in result text displayed is uppercase)
`'JAN': 'JAN'`
`'FEV': 'FÉV'`
etc ...
no result

What's the problem?

Please help
11 years ago

The first approach works for me (I assume multilanguage is enabled on the site)

11 years ago

Please, tell me more so that I can reach the point!

here is the fr.yaml document the way it is now in user/languages:

YAML
Feb: Fév
Apr: Avr
May: Mai
Jun: Jui
Jul: Jui
Aug: A
Dec: Déc

unfortunately, no result!

Jan, Mar, Sep, Oct, Nov are actually same in en and fr so not needed.

Please tell me how you had it written to work.

Thanks in advance

11 years ago

in the above code, these are the only strings of the whole fr.yalm document in user/languages

11 years ago

I mean, there is nothing that says fr there...

11 years ago

how can i indicate to twig translation filter |tin _blog.item.html.twig that the translation is to be made to fr therefore fr.yaml ?

11 years ago

the |t twig filter will automatically use the current active language. There is no need to tell it which one that is.

11 years ago

☆ Thank you very much for reply: I have tried hard to get to the point but yet not possible (it is one o'clock at night in France so feeling now very tired also probably)... ♪

In your opinion, what could possibly the difficulty?

I precise: my default language is fr, then comes ja in second, then en in third.

Strangely, with _blog.item.html.twig, whatever I do in fr.yaml, it's like nothing... My dates are still en ...

11 years ago

Perhaps tomorrow you can provide a zip of your site for us to look at and inspect, and that will make things clearer :)

11 years ago

just zip it up, stick it on dropbox or something, and send us a link to devs (at) getgrav.org

11 years ago

☆ I really apreciate the support / help ♪ with time difference it's better to do it before sleeping may be... Understood
Again, thank you for assistance...

11 years ago

@rhukster:

I am very proud to tell you that I finally solve the yesterday problem on date (how painful it has been!).

The issue was that I was working on template _blog_item.html.twig and the html page on another template blog_item.html.twig ...

Now I got to the point, having my date in fr and ja and japanese just the way it has to be.

Previous reply on italian footer with what you explained about definition of constant that made me translate my footer and from there try again on dates.

Could not understand why it would not work as I was doing similar, I erased the code and realised it was NOT the right template ... It's stupid but finally ...

Thank you again for your help

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1346 9 years ago
Archive · by Muut Archive, 9 years ago
2 933 9 years ago
Archive · by Muut Archive, 9 years ago
2 4060 9 years ago
Archive · by Muut Archive, 9 years ago
1 2945 9 years ago
Archive · by Muut Archive, 9 years ago
3 1117 9 years ago