Middleman I18n generating translated files under /en/en/filename - internationalization

A default install of Middleman 4.1.10 with i18n 0.7.0 on Ruby 2.3.1p112 generates nested duplicate locales folders with broken links for the non-default language.
E.g, if Swedish is the default language, the translated english files get generated under /en/en/, with duplicates under /en/sv/, and files with broken links in swedish under /en/. The site´s primary language´s files get created correctly under /sv/. Changing the default language to English renders the same error, but then under /sv/sv/, with correct files and links under /en/ instead.
I stumbled on this when evaluating Middleman by converting an existing bi-lingual site. The same path/filename/link pattern is also reproducible on a default installation of Middleman with minimal configuration, as shown here.
I really can´t figure out if I went wrong somewhere, or if this is a bug in Middleman´s I18n module. Found nothing even remotely reminding of this by googling, on Stackoverflow, or Middleman´s documentation or bug reports, which makes me suspect I´m missing something embarrasingly obvious.
This is my setup:
config.rb
page '/*.xml', layout: false
page '/*.json', layout: false
page '/*.txt', layout: false
set :relative_links, true
activate :i18n, :mount_at_root => :sv
Yes, I think I've tested all the other possible documented combinations of :i18n without any result. Manually setting the order between languages by :langs => [:en, :sv] only renders the same erroneous directory structure under sv.
locales/en.yml
---
en:
index: Home
news: News
paths:
index: index
news: news
locales/sv.yml
---
sv:
index: Hem
news: Nyheter
paths:
index: index
news: nyheter
source/layouts/layout.erb
<!doctype html>
<html>
<head>
<title></title>
<!-- The only change from defaults: -->
<%= link_to t(:index), t("paths.index") + ".html" %>
<%= link_to t(:news), t("paths.news") + ".html" %>
<%= stylesheet_link_tag :site %>
<%= javascript_include_tag :all %>
</head>
<body class="<%= page_classes %>">
<%= yield %>
</body>
</html>
source/localizable/en/index.html.erb
---
title: English index
---
English index
source/localizable/en/news.html.erb
---
title: English news
---
English news
source/localizable/sv/index.html.erb
---
title: Swedish index
---
Swedish index
source/localizable/sv/news.html.erb
---
title: Swedish news
---
Swedish news
Obviously I expected this:
├── en
│   ├── index.html
│   └── news.html
│
└── sv
├── index.html
└── nyheter.html
But got this:
├── en
│   ├── en
│   │   ├── index.html # Both files with correct english translations and
│   │   └── news.html # links, but only linked in the /en/en/ directory
│   │
│   ├── index.html # Both files with swedish translations
│   ├── nyheter.html # and functioning links in swedish
│   │
│   └── sv
│   ├── index.html # Both files with swedish translations and
│   └── news.html # links within the /en/sv/ directory
│  
└── sv
├── index.html # Both files with correct swedish
└── nyheter.html # translations and links

Related

How to connect two Candy Machines?

I need to create a collection with a total of 100 NFTs, where the first 10 (IDs 0 to 9) will be minted to the same wallet from the start, and the remaining 90 will have the possibility to be minted through a web page.
I understand that the procedure would be as follows:
Create a CMv2 with a total of 10 assets.
Mint all of them (because the minting is random, it must be done before adding the remaining NFTs).
Create the second CMv2 with the remaining 90 assets. I must specify the address of the mint created in the first CMv2 (the "collection mint address") with the -m parameter.
However, I encounter several errors when doing this:
Case 1:
private.json -> "number": 10
public.json -> "number": 90
assets
├── private
│ ├── 0.json
│ ├── 0.png
│ ├── ...
│ ├── 9.json
│ └── 9.png
└── public
├── 10.json
├── 10.png
├── ...
├── 99.json
└── 99.png
config
├── private.json
└── public.json
Case 2 (same file structure as above):
private.json -> "number": 10
public.json -> "number": 100
Case 3:
private.json -> "number": 10
public.json -> "number": 90
assets
├── private
│ ├── 0.json
│ ├── 0.png
│ ├── ...
│ ├── 9.json
│ └── 9.png
└── public
├── 0.json
├── 0.png
├── ...
├── 89.json
└── 89.png
config
├── private.json
└── public.json
Case 4 (same file structure as above):
private.json -> "number": 10
public.json -> "number": 100
All 4 cases return the same error: Error Number: 6003. Error Message: Index greater than length!.
I had the same issue not to long ago take a look here: One Collection, Multiple Candy Machines
First of all, I recommend using SUGAR CLI to upload & deploy the Candy Machines - the experience is smoother. If you are on Windows you can use WSL2. I also recommend getting a custom RPC, take a look at Quiknode - it's easy to setup.
To upload and then deploy the public collection:
sugar upload assets/public -c config/public.json --cache .cache/public.json -k <WALLET KEYPAIR.json> -l debug -r <RPC ENDPOINT URL>
sugar deploy -c config/public.json --cache .cache/public.json -k <WALLET KEYPAIR.json> -l debug -r <RPC ENDPOINT URL>
Repeat the same steps as above for the private collection (just change private wherever there is public).
To set the same collection using SUGAR:
sugar collection set --cache .cache/public.json -k <WALLET KEYPAIR.json> --candy-machine <CANDY MACHINE ID> --collection-mint <COLLECTION ADDRESS> -r <RPC ENDPOINT URL>
Repeat for private assets.
I've managed to show total number of NFTs on UI by connecting to the private machine and the public machine (you however cannot mint from the private machine using the UI) - this behavior is not supported by default, you are going to have to do some coding for that.
And regarding the index problem, the different configurations should have done the trick (private.json & public.json) but if Metadata is the problem I used a python script to renumber the indexes properly - if that is something you are interested in I can provide.
Once,you have uploaded your assets and created a Candy Machine then you cannot add or remove assets from that Candy Machine So to answer this question on how to merge two Candy Machine Together you can create a Single Collection/Parent NFT and point both the Candy machine assets to that Collection/Parent NFT. You can use the tool metaboss to do that

Puppet unable to find my .erb template but finds other files OK?

No one has been able to explain this inside my company so if you are able to solve this KUDOS to you!
Inside my puppet repo I have setup as follows:
environment/ops/modules/papertrail
├── files
│ ├── elasticsearch_log_files.yml
│ ├── log_files.yml
│ └── remote_syslog.conf
|
└── manifests
├── elasticsearch.pp
└──init.pp
└── templates
└── elasticsearch_log_files.yml.erb
MY elasticsearch.pp file contains the following:
class papertrail::elasticsearch inherits papertrail {
$source = "puppet:///modules/papertrail"
file { "/etc/log_files.yml" :
mode => 0644,
owner => root,
group => root,
ensure => present,
source => "$source/elasticsearch_log_files.yml",
}
}
Now when I try to change the last line to:
"$source/elasticsearch_log_files.yml.erb",
or
"$source/templates/elasticsearch_log_files.yml",
Puppet errors out and says that it can't locate the file:
Error: /Stage[main]/Papertrail::Elasticsearch/File[/etc/log_files.yml]: Could not evaluate: Could not retrieve information from environment ops source(s) puppet:///modules/papertrail/elasticsearch_log_files.yml.erb
What is strange is that when I use the following stanza to just include the yml file instead of erb it works fine and the file gets populated on the target:
"$source/elasticsearch_log_files.yml",
How can I include my erb? I have dynamic variables that I need to assign to the configuration file log_files.yml and I am so far unable to do so =(
This is solved. I didn't add the template directory to my git commit so once added with git add . it worked.

An addon's ToggleButton icon is not displayed when used in Tor browser

I have a question about a strange behaviour of an addon used in Firefox (40) and Tor browser 5.0.1 (Firefox 38.2.0). The goal would be to have a working addon for both environments.
This simple example was created with jpm init and slightly adapted to highlight the ToggleButton problems. While the ToggleButton and its icon is displayed nicely in Firefox via jpm run, Tor seems to have problems finding the icon files and displays nothing. For importing the addon in Tor I've used jpm xpiand installed the addon via the addon-manager.
My current directory layout has the following structure:
├── README.md
├── data
│   ├── skull-16.png
│   ├── skull-32.png
│   ├── skull-48.png
│   └── skull-64.png
├── icon.png
├── index.js
├── package.json
└── test
└── test-index.js
And this is the content of the index.jsfile:
const self = require('sdk/self');
const { ToggleButton } = require("sdk/ui/button/toggle");
// a dummy function, to show how tests work.
// to see how to test this function, look at test/test-index.js
function dummy(text, callback) {
callback(text);
}
let button = ToggleButton({
id: "skull-link",
label: "Skull Master",
icon: {
"16": "./skull-16.png",
"32": "./skull-32.png",
"48": "./skull-48.png",
"64": "./skull-64.png"
},
onChange: function() {
console.log("toggle")
},
bagde: 0
});
exports.dummy = dummy;
Nothing special, I have just added the ToggleButton part.
I haven't found any clashes between the API in Firefox 38 and 40, so I'm clueless what might trigger this behavior. Thank you all for your help.
You can find the example in as zip-file here: sample addon
It was actually a simple one but took me very long to figure out. I found the answer in the post ndm13's answer. If you have problems with addons working in Firefox but not Tor, append
"permissions": {"private-browsing": true}
to your package.json. Tor browser is always in private browsing mode.

How to set up custom bash environment for different users with puppet?

I'm just getting started with puppet (and vagrant) to set up the development environment for our team, which consists of 8+ developers, each of which have their particular bash configuration, etc. I've got all the software installed on the system to quickly deploy new development virtual machines, but I'm not sure the best way to set up the development environment for each particular user in an automated way (we will end up having several development environments and it would be convenient to write this once and be done).
For example, I'd like to set up a user joe, clone Joe's configuration repo from github, and then run a script in that github repository to set up the environment for Joe. Any suggestions for how to do this for Joe as well as Jimmy, James, Julie, Jane, Jim, Jake, and Jimbo?
In case its any help, the development machines will almost certainly be ubuntu systems.
In addition to #Matt's suggestion, I created a custom puppet module that instantiates the configuration environment for each individual based on their github preferences. The resulting puppet module users looks something like this:
users/
├── manifests
│   ├── init.pp # base level configurations for all users
│   ├── jake.pp # custom setup for jake
│   ├── james.pp # custom setup for james
│   ├── jane.pp # custom setup for jane
│   ├── jim.pp # custom setup for jim
│   ├── jimbo.pp # custom setup for joe
│   ├── jimmy.pp # custom setup for jimmy
│   ├── joe.pp # custom setup for julie
│   └── julie.pp # custom setup for jimbo
└── templates
The relevant tidbit is in the custom setup files for each user. For example, here's what jim.pp might look like:
class users::jim {
# make sure that all base configuration in init.pp is set up first
require users
# add the user here
user { 'jim':
# comment => 'Dean Malmgren',
home => '/home/jim',
shell => '/bin/bash',
uid => 201,
managehome => 'true',
groups => ['sudo', 'vagrant'],
provider => 'useradd',
password => '$6$kxHLEuHW$78m3zHVLu0XUUDaU4bT.PEg./FfcloJiWml',
}
# clone the repository the first time
exec { 'jim-clone-dotfiles':
command => 'git clone git://github.com/jim/dotfiles.git && python dotfiles/create_softlinks.py',
cwd => '/home/jim',
creates => '/home/jim/dotfiles',
user => 'jim',
group => 'jim',
require => [ Package['git'] ],
}
# fetch and update if jim decides to update his dotfiles repo
exec { 'jim-update-dotfiles':
command => 'git merge --ff-only origin/master && python create_softlinks.py',
cwd => '/home/jim/dotfiles',
unless => 'git fetch && git diff --exit-code origin/master',
user => 'jim',
group => 'jim',
require => Exec['jim-clone-dotfiles'],
}
}
You could use a puppet fact in the vagrant file to set the username and pass this through to your puppet manifests. Something like the following:
Vagrant.configure("2") do |config|
config.vm.provision :puppet do |puppet|
puppet.facter = {
"user_name" => ENV['USER']
}
end
end
This would pass the current logged in username through to puppet and then within your manifest files you could use the variable "$user_name" within your git commands to checkout the correct users repo and do any other related tasks.

Set / change + add Sinatra views folder

I am learning sinatra, and I am trying to create simple website. This is my web directory tree:
├── app.rb
│
├── admin
│   └── views
│  └── admin.rb
├── models
├── static
│  
└── views
and now I want render views just for admin. In other words: I have 2 views folder in different locations, admin for admin controller and views, and another views is for homepage.
Add config.ru file in root application folder
require './app'
require './admin/admin'
# run MyApp
run Rack::URLMap.new("/" => MyApp.new, "/admin" => AdminApp.new)
In app.rb
require 'sinatra'
require 'haml'
class MyApp < Sinatra::Base
get "/app" do
haml :app
end
end
In admin.rb
# admin.rb
class AdminApp < Sinatra::Base
get "/" do
haml :index
end
end
Finally in console rackup -p PORTNUMBER example
rackup -p 4000
Update
Reference to Gist

Resources