So I have a bunch of translated keys set up like this:
|-- en
homepage.json
login.json
signup.json
|-- de
homepage.json
login.json
signup.json
I want to upload these to PhraseApp via their command line tool. Basically, it reads a .phraseapp.yml file for config settings and runs.
My current .phraseapp.yml looks like this:
phraseapp:
access_token: 123456789
project_id: 123456789
file_format: nested_json
push:
sources:
- file: <locale_name>/*.json
params:
file_format: nested_json
pull:
targets:
- file: <locale_name>/*.json
params:
file_format: nested_json
However, this setup just uploads all of these json files to the en and de locales, completely ignoring the namespace implied by filename. How can I retain namespaces with PhraseApp?
At the very least, I'd like to be able to include the namespace as a tag, something like this:
phraseapp:
access_token: 123456789
project_id: 123456789
file_format: nested_json
push:
sources:
- file: <locale_name>/<namespace>.json
params:
file_format: nested_json
tags: <namespace>
pull:
targets:
- file: <locale_name>/*.json
params:
file_format: nested_json
This obviously doesn't work, as it causes PhraseApp to look for a file literally named <namespace>. Any ideas?
Try using the placeholder <tag> instead of <namespace>. This way the keys will be tagged with the name of the file they belong to when running phraseapp push.
In order to put back the keys into the right file when downloading the locales again (phraseapp pull), you have to setup multiple target file paths with the tag-parameter respectively.
According to this, your .phraseapp.yml can look something like this:
phraseapp:
access_token: ...
project_id: ...
file_format: nested_json
push:
sources:
file: ./<locale_name>/<tag>.json
pull:
targets:
# homepage
-
file: ./<locale_name>/homepage.json
params:
tag: "homepage"
# login
-
file: ./<locale_name>/login.json
params:
tag: "login"
# signup
-
file: ./<locale_name>/signup.json
params:
tag: "signup"
The workflow is described more detailed here: https://phraseapp.com/docs/guides/working-with-phraseapp/structuring-localization-files/#keeping-separate-files
Have a nice weekend and best regards!
Cornelius
Related
I have a directory containing json files, and i want to use github actions to create a new file in the repository, that contains an array of all those json files.
for example, the directory <my-repo>/configurations contain the files a.json, b.json, I want to create a new file called configs.json contains [<a.json content>,<b.json content>].
The creation must be done dynamically.
Any suggestions?
solution for config files sitting under \configs directory:
name: build unified config file
on: [push]
jobs:
build_file:
name: build unified config file
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout#v2
- name: setup python
uses: actions/setup-python#v2
with:
python-version: 3.8
- name: Run script
uses: jannekem/run-python-script-action#v1
with:
script: |
import os, json, shutil
with open("unified.json", "r+") as t:
t.truncate(0)
t.write('[')
for filename in os.scandir('configs'):
print(filename)
with open(filename, "r") as f:
content = f.read()
t.write(content)
t.write(',')
t.write(']')
barak = open("unified.json", "r+")
contentb = barak.read()
print(contentb)
- name: push file to main
uses: EndBug/add-and-commit#v9
with:
add: 'unified.json'
committer_name: Committer Name
committer_email: mail#example.com
default_author: github_actor
message: 'Update unified config file'
push: true
I have a lot of json files in my bucket in GCS and I need to create a table for each one.
Normally, I do it manually in BigQuery: selecting the format (json), giving it a name and using automatically detected schema.
Is there any way of creating multiple tables at once using data from GCS?
Disclaimer: I have a blogpost authored on this topic at https://medium.com/p/54228d166a7d
Essentially you can leverage Cloud Workflows, to automate this process.
a sample workflow would be:
ProcessItem:
params: [project, gcsPath]
steps:
- initialize:
assign:
- dataset: wf_samples
- input: ${gcsPath}
# omitted parts for simplicity
- runLoadJob:
call: BQJobsInsertLoadJob_FromGCS
args:
project: ${project}
configuration:
jobType: LOAD
load:
sourceUris: ${gcsPath}
schema:
fields:
- name: "mydate"
type: "TIMESTAMP"
- name: "col1"
type: "FLOAT"
- name: "col2"
type: "FLOAT"
destinationTable:
projectId: ${project}
datasetId: ${dataset}
tableId: ${"table_"+output.index}
result: loadJobResult
- final:
return: ${loadJobResult}
BQJobsInsertLoadJob_FromGCS:
params: [project, configuration]
steps:
- runJob:
call: http.post
args:
url: ${"https://bigquery.googleapis.com/bigquery/v2/projects/"+project+"/jobs"}
auth:
type: OAuth2
body:
configuration: ${configuration}
result: queryResult
next: queryCompleted
- queryCompleted:
return: ${queryResult.body}
In this answer you have a solution to recursively go through your bucket and load csv files to BQ. You can adapt this code with for instance:
gsutil ls gs://mybucket/**.json | \
xargs -I{} echo {} | \
awk '{n=split($1,A,"/"); q=split(A[n],B,"."); print "mydataset."B[1]" "$0}' | \
xargs -I{} sh -c 'bq --location=YOUR_LOCATION load --replace=false --autodetect --source_format=NEWLINE_DELIMITED_JSON {}'
This is if you want to run a load job in parallel manually.
If you want to add automation, you can use workflows as #Pentium10 recommends, or plug the Bash command into a Cloud Run instance coupled with a Scheduler for instance (you can look at this repo for inspiration)
I'm writing AWS CloudFormation template (using yaml) which creates AWS Service Catalog Product.
I'm getting the template for the product using parameter S3FilePath which has a value like the above path: https://bucket.s3-eu-west-1.amazonaws.com/template.yml.
The URL to the file needs to be send in a JSON format as shown here (this example works):
Resources:
Type: AWS::ServiceCatalog::CloudFormationProduct
Properties:
Description: Example Product
Distributor: xyz
Name: ExampleProduct
Owner: xyz
ProvisioningArtifactParameters:
- Description: Example Product
Info: { "LoadTemplateFromURL": "https://bucket.s3-eu-west-1.amazonaws.com/template.yml" }
Name: Version1
I tried to replace the URL using !Sub and !Ref as shown below:
Parameters:
S3FilePath:
Type: String
Description: file name
Resources:
Type: AWS::ServiceCatalog::CloudFormationProduct
Properties:
Description: Example Product
Distributor: xyz
Name: ExampleProduct
Owner: xyz
ProvisioningArtifactParameters:
- Description: Example Product
Info: !Sub
- '{ "LoadTemplateFromURL": "${FILEPATH}" }'
- {FILEPATH: !Ref S3FilePath}
Name: Version1
But the CloudFormation stack fails with the error: "invalid input".
I guess I am building the JSON in a wrong way, I tried to use \ before each ' " ' but it didn't help either and I couldn't find an example which explain how to build this correctly. There is no problem with the S3FilePath parameter.
Can you please advice how to use the !Sub and !Ref correctly to build the JSON? Thanks.
Here is an example: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-sub.html#w2ab1c25c28c59c11
Despite the documentation saying the Info parameter is JSON, the example shows just a name/value pair (Map): https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-servicecatalog-cloudformationproduct-provisioningartifactproperties.html
Try formatting your string as
Info: !Sub
- "LoadTemplateFromURL": "${FILEPATH}"
- {FILEPATH: !Ref S3FilePath}
You can reference any Parameters or LogicalResourceId directly inside a !Sub like so:
ProvisioningArtifactParameters:
- Description: Example Product
Info: !Sub '{ "LoadTemplateFromURL": "${S3FilePath}" }'
Name: Version1
This should work totally fine. The way you were doing substitutions is useful when you want to use conditions and/or mapping inside a !Sub.
I think it should be simply:
ProvisioningArtifactParameters:
- Description: Example Product
Info:
LoadTemplateFromURL: !Ref S3FilePath
Name: Version1
This is at least what I have in my own AWS::ServiceCatalog::CloudFormationProduct templates.
ProvisioningArtifactParameters:
- DisableTemplateValidation: false
Info:
LoadTemplateFromURL: !Ref S3FilePath
I'm self-taught/totally new to Jekyll and Github Pages and was wondering how to go about opening a URL in a new tab with markdown in the config.yml page.
This is the website theme I'm using. I want the last 'github' link to open in a new tab, instead of the default, which is opening in the current tab.
The _config.yml looks like this:
# # # # # # # # # # # # #
# K i k o - p l u s #
# # # # # # # # # # # # #
# Basic
name: "Kiko Plus"
author:
facebook: your-id
youtubeUser: your-id
youtubeChannel: your-id
twitter: your-id
github: your-id
stackoverflow: your-id
quora: your-id
linkedin: your-id
pinterest: your-id
googlePlus: your-id
instagram: your-id
reddit: your-id
medium: your-id
tumblr: your-id
email: your-id#your-email.com
copyright:
year: 2017
name: Kiko
# Google-analytics
google-analytics:
id: ""
# Disqus
disqus:
id: "kiko-plus"
# URL
url: "https://AWEEKJ.github.io" # the base
hostname & protocol for your site
# url: "http://localhost:4000" # use this url when
you develop
baseurl: "/Kiko-plus" # the subpath of your site
# http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
timezone: Asia/Seoul
permalink: /:year-:month-:day/:title/
# Pagination
paginate: 5
paginate_path: /page:num/
# Markdown
markdown: kramdown
kramdown:
input: GFM
# Navigation
nav:
- name: "About"
url: "/about"
- name: "Archive"
url: "/archive"
- name: "Tags"
url: "/tags"
- name: "Github"
url: "https://github.com/AWEEKJ/Kiko-plus"
# Sass
sass:
sass_dir: _sass
style: :compressed
# Scopes
defaults:
-
scope:
path: ""
type: "pages"
values:
layout: "page"
-
scope:
path: ""
type: "posts"
values:
layout: "post"
# jekyll-seo-tag,
gems:
- jekyll-seo-tag
- jekyll-paginate
- jekyll-admin
exclude: [vendor]
To do this in any basic markdown post, naturally you'd do
[a link](http://example.com){:target="_blank"}
But since this link is in the site setup, that doesn't work. I've searched a ton and tried 5 or 6 different recommendations but to no avail.
Any ideas? Would be uber appreciated!!!!
You need to add target="_blank" to index.html line 12 as follow:
{{ nav.name }}
I found a plugin that automatically sets any external URL to open in a new tab:
https://rubygems.org/gems/jekyll-target-blank
Add the following to your site's Gemfile
gem 'jekyll-target-blank'
and add the following to your site's
_config.yml
plugins:
- jekyll-target-blank
You may also need to run bundle install to install the new Gem
{:target="_blank"} works for me:
[text](http://url){:target="_blank"}
How can I pull a default scope/value from my Jekyll _config.yml file into my default layout?
Here is part of the _config.yml
# default settings
defaults:
-
scope:
path: "" # an empty string here means all files in the project
type: posts
values:
author: ME
layout: post
class: article
I want to print something simple like {{ site.defaults.scope.type }}
You can simply get the value class by using page.class in a page that conforms to the path and type specified. For example:
config.yml
defaults:
-
scope:
path: ""
type: posts
values:
class: a post
-
scope:
path: ""
type: not_posts
values:
class: not a post
_posts/****-**-**-post.html
---
layout: post
---
{{ page.class }}
Output
a post