Silverstripe template i18n translation - internationalization

I'm trying to use i18n functionality in templates in Silverstripe.
In a template ss file, I have the following:
<h4 class="red-underline"><%t Namespace1.Replace "ToBeReplaced" %></h4>
And I have the following in /lang/en_US.yml:
en:
Namespace1:
Replace: 'ReplacedString'
I have also added this to my _config.php:
use SilverStripe\i18n\i18n;
i18n::set_locale('en_US');
And this in my config.yml:
SilverStripe\i18n\i18n:
common_locales:
en_US:
name: English (USA)
native: English
But the string "ToBeReplaced" is not replaced.
The documentation I can find about this, is:
https://docs.silverstripe.org/en/4/developer_guides/i18n/
Am I missing something?

The problem was that the lang folder was added to the wrong location.
It should be located in /mysite/lang/

Related

Folder _data in theme directory does not get the values

I'm making a Jekyll theme using the command jekyll new-theme mytheme. I want to add translations to this theme, so I created the file _data/translations.yml into the root directory. This is its content:
---
en:
post: "Post"
es:
post: "Artículo"
I get the information with this expressions:
{% assign t = site.data.translations %}
{{ t[site.lang]['post'] }}
This setup only works if I move the _data/translations.yml file to my Jekyll website directory, created through the command jekyll new mysite.
Are the data files out of themes territory? Should I place this yml file in another directory? If it's not possible to use it in the themes territory, I would like to set a default value: how can I achieve this?
Thanks in advance.
As of Jekyll 4.0, yes, data files inside a theme-gem are not read.
You'll need to use a plugin named jekyll-data (authored by me).
If you plan to publish the theme for other users, I recommend adding the plugin as a runtime dependency in the theme's gemspec. Otherwise, simply adding the plugin to the :jekyll_plugins group in the site's Gemfile will suffice.

SilverStripe i18n Textcollector Task not loading

I'm using SilverStripe 3.4 and trying to translate my website. But on Windows I can't run the http://localhost/dev/tasks/i18nTextCollectorTask I get ERR_CONNECTION_RESET.
I tried to create the translation files manually and added them to the mysite directory:
/lang/de_DE.php
/lang/en_GB.php
containing the following code:
<?php
global $lang;
$lang['en_GB']['Header']['Contact'] = 'Get in Contact';
and in the Template:
<h5><% _t('Header.Contact', 'Nehmen Sie Kontakt auf') %></h5>
but the Text is always in German ... Why is it not translating and why can't I open the Text Collector on Windows?
Update
I started the collector via cli
framework/sake dev/tasks/BetterI18nTextCollectorTask "targetlocale=de,en&module=themes/xxx&flush=1"
and there are two yml files in my theme/lang directory. But the text is still not translating.
de.yml:
de:
Footer.ss:
__IMAGE: '%2.2s'
Header:
__Contact: 'Nehmen Sie Kontakt auf'
en.yml
en:
Footer.ss:
__IMAGE: '%2.2s'
Header:
__Contact: 'Get in Contact'
To utilize the text collector task, you'd have to install PHPUnit 3.7.
You can add it as a dev-dependency via composer, so that it doesn't get included in a production environment:
composer require --dev phpunit/phpunit ~3.7
As an alternative to the text-collector task, you could also use the better-i18n module:
composer require --dev zauberfisch/silverstripe-better-i18n
It also requires PHPUnit, so that installation is a must.
Language files written in PHP have been deprecated quite a long time ago. You should switch to YAML based language files, which look like this:
# File stored in lang/en.yml
en:
Header:
Contact: 'Get in contact'
# etc.
Update: There's also an updated syntax how to do translations in templates. You're using the old syntax that's going to be deprecated
This:
<h5><% _t('Header.Contact', 'Nehmen Sie Kontakt auf') %></h5>
should become this:
<h5><%t Header.Contact 'Nehmen Sie Kontakt auf' %></h5>
Relevant documentation.

Render markdown from a yaml multiline string in a Jekyll data file

When using Jekyll data files I would like to store a formatted description, primarily to that I can have links in it. It works with HTML.
- name: Project name
description: >
I want to include a link
That renders properly in the generated page when included with {{ project.description }}.
Can I use markdown instead of HTML? I would prefer to do this:
- name: Project name
description: >
I want to include a [link](http://foobar.com)
Turns out Liquid supports filters, but doesn't have one for processing markdown. Thankfully Jekyll adds it's own set of handy filters which includes markdownify so now I can do this:
{{ project.description | markdownify }}

How do I setup the Date URLs Plugin for DocPad?

I've recently converted from Octopress to Docpad and couldn't be happier. I like everything, but one thing bothers me. At the moment all paths on my site are built directly from the filename, e.g. www.site.com/posts/yyyy-mm-dd-title/. What I want to get is www.site.com/posts/yyyy/title. I found the Date URLs plugin, but cannot understand how to set it up. I tried inserting the relevant part into docpad.coffee as follows:
docpadConfig =
plugins:
dateurls:
cleanurl: true
trailingSlashes: true
collectionName: 'posts'
dateFormat: '/YYYY'
templateData:
site:
But nothing seems to change. The collection is defined as follows:
posts: ->
#getCollection("html").findAllLive({relativeOutDirPath:'blog'},[date:-1]).on "add", (model) ->
model.setMetaDefaults({layout:"post"})
--
EDIT (in response to Lukasz Gornicki)
A sample of metadata from the blog folder:
---
title: "Les Sapeurs"
date: 2014-09-25 07:39
comments: false
language: english
tags: video
keywords: anton zujev, antzoo, zujev, sapeurs, style, congo
description: Les Sapeurs are fashionistas from Congo, whose style is a political and social outcry.
---
A sample of metadata from the cast folder:
---
title: "Utan 7"
date: 2015-02-27 06:52
podfeed: utan
comments: true
---
I didn't try the debug mode before. Now I did, but I don't see anything special in the log. Here's the log file.
I've installed the plugin on my blog to check it out. I think there is a bug in documentation or it is just supper misleading. Documentation doesn't explicitly say that the url is build against the date metadata with dateFormat configuration and file basename without the date. I copied your configuration use it agains my blog with post 2015-02-16-test-test.html.md with metadata: date: 2014-09-25 9:49.
result url: http://localhost:9778/2014/test-test/
So the plugin works. Do you think that docpad doesn't pick up any configuration for the plugin? If you are configuring docpad with docpad.coffee I suggest you to validate the file, if it is created according to coffeescript rules and you have right indentation. Some time ago I had a situation that my config file grew a lot and some of the config was not picked up because of indentation.
Or just give access to the project so I can see and tell you what is wrong.
MORE DETAILS TO THE ANSWER AFTER CHECKING THE PROJECT:
Filename can have a date. The plugin uses regex to take just the string out of the filename - basename.
Locally I've commented out your hook into the renderBefore event, installed the plugin, added your config and all works as expected if it comes to the urls. So I get a URL like /2014/movie-quotes/
On the other hand it works when the server is started, but when I look on the out dir and try to generate the static content, it looks like the plugin doesn't work. Is this what you mean when saying that plugin doesn't work?

Generated markdown file with rake post command

I am deploying my github blog using jekyll-bootstrap.I try to modify Rakefile to change the result of $rake post title="test" and then this command will generate a file named test.md(without date) in _posts directory,but unfortunately,when I run
$jekyll serve
locally,it seems that jekyll do not think test.md is an available post,what shoul I do?
I think that what you want it's custom url for your posts.
Leave alone the rake task, because the final post filename is generated in accordance with a permalinks pattern see permalinks documentation
By default you posts are generated following the default pattern /:categories/:year/:month/:day/:title/index.html
If you want to change this pattern, in your _config.yml, use permalink key :
permalink: /blog/:year/:month/:day/:title/filename.html

Resources