Skip to content

Instantly share code, notes, and snippets.

@MarcoIeni
Created August 9, 2018 20:54
Show Gist options
  • Save MarcoIeni/685292e779a61faf01f28972ff80d40f to your computer and use it in GitHub Desktop.
Save MarcoIeni/685292e779a61faf01f28972ff80d40f to your computer and use it in GitHub Desktop.
Localize json resume in different languages

JSON Resume internationalization

A simple way to add internationalization feature to the JSON Resume project.

Create a different entry for each field that you want to localize, named with the language and the name of the field separated by an underscore. For example if you want to create an italian version and an english version of your summary do the following:

"basics": {
  "name": "Richard",
  "label": "Programmer",
  ...
  "en_summary": "Richard hails from Tulsa. He has earned degrees from the University of Oklahoma and Stanford.",
  "it_summary": "Richard proviene da Tulsa. Ha conseguito una laurea presso l'Università dell'Oklahoma e di Stanford.",
  ...
}

For a complete example you can look at the resume.json file.

Then execute the command python3 localize.py in the same directory of your json resume. In this way you will create a directory for each language specified in the different fields. Each directory contains a valid resume.json that only contains the common fields (the ones without and underscore) and the ones related to that language.

Therefore, if we go on with the previous example, inside the it directory you will have a resume.json that has these fields:

"basics": {
  "name": "Richard",
  "label": "Programmer",
  ...
  "summary": "Richard proviene da Tulsa. Ha conseguito una laurea presso l'Università dell'Oklahoma e di Stanford.",
  ...
}
import json
import copy
import os
import collections
RESUME_FILEPATH = "resume.json"
class Localizer:
def __init__(self):
self.resume = json.load(
open(RESUME_FILEPATH), object_pairs_hook=collections.OrderedDict)
self.found_languages = set()
def localize(self):
self.__find_languages(self.resume)
for l in self.found_languages:
self.__process_language(l)
def __find_languages(self, dictionary):
for key, value in dictionary.items():
if isinstance(value, dict):
self.__find_languages(value)
else:
if "_" in key:
self.found_languages.add(key.split("_")[0])
def __localize_resume(self, resume, language):
if not isinstance(resume, dict):
# we are in an array of string
return
for key in list(resume.keys()):
value = resume[key]
if isinstance(value, dict):
self.__localize_resume(value, language)
elif isinstance(value, list):
for v in value:
self.__localize_resume(v, language)
else:
if "_" in key:
if language + "_" in key:
new_key = key.split(language + "_")[1]
change_key(resume, key, new_key)
else:
del resume[key]
def __process_language(self, language):
localized_resume = copy.deepcopy(self.resume)
self.__localize_resume(localized_resume, language)
if not os.path.exists(language):
os.makedirs(language)
output_filepath = language + "/" + RESUME_FILEPATH
with open(output_filepath, "w") as outfile:
json.dump(localized_resume, outfile, indent=2, ensure_ascii=False)
def change_key(dictionary, old, new):
for _ in range(len(dictionary)):
k, v = dictionary.popitem(False) # pop first item
dictionary[new if old == k else k] = v
def main():
localizer = Localizer()
localizer.localize()
if __name__ == "__main__":
main()
{
"basics": {
"name": "Richard",
"label": "Programmer",
"picture": "",
"email": "mail@mail.com",
"phone": "(912) 555-4321",
"website": "http://richardhendricks.com",
"en_summary": "Richard hails from Tulsa. He has earned degrees from the University of Oklahoma and Stanford. (Go Sooners and Cardinals!) Before starting Pied Piper, he worked for Hooli as a part time software developer. While his work focuses on applied information theory, mostly optimizing lossless compression schema of both the length-limited and adaptive variants, his non-work interests range widely, everything from quantum computing to chaos theory.",
"it_summary": "Richard proviene da Tulsa. Ha conseguito una laurea presso l'Università dell'Oklahoma e di Stanford. (Go Sooners and Cardinals!) Prima di iniziare Pied Piper, ha lavorato per Hooli come sviluppatore di software part-time. Mentre il suo lavoro si concentra sulla teoria dell'informazione applicata, per lo più ottimizzando lo schema di compressione senza perdita di entrambe le varianti di lunghezza limitata e adattiva, i suoi interessi non lavorativi variano ampiamente, tutto dall'informatica quantistica alla teoria del caos.",
"location": {
"address": "2712 Broadway St",
"postalCode": "CA 94115",
"city": "San Francisco",
"countryCode": "US",
"region": "California"
},
"profiles": [
{
"network": "Twitter",
"username": "neutralthoughts",
"url": ""
},
{
"network": "SoundCloud",
"username": "dandymusicnl",
"url": "https://soundcloud.com/dandymusicnl"
}
]
},
"work": [
{
"company": "Pied Piper",
"en_position": "CEO/President",
"it_position": "Presidente",
"website": "http://piedpiper.com",
"startDate": "2013-12-01",
"endDate": "2014-12-01",
"en_summary": "Pied Piper is a multi-platform technology based on a proprietary universal compression algorithm that has consistently fielded high Weisman Scores™ that are not merely competitive, but approach the theoretical limit of lossless compression.",
"it_summary": "Pied Piper è una tecnologia multipiattaforma basata su un algoritmo di compressione universale proprietario che ha costantemente messo in campo elevati Weisman Scores™ che non sono semplicemente competitivi, ma si avvicinano al limite teorico della compressione lossless.",
"highlights": [
"Build an algorithm for artist to detect if their music was violating copy right infringement laws",
"Successfully won Techcrunch Disrupt",
"Optimized an algorithm that holds the current world record for Weisman Scores"
]
}
],
"volunteer": [
{
"organization": "CoderDojo",
"position": "Teacher",
"website": "http://coderdojo.com/",
"startDate": "2012-01-01",
"endDate": "2013-01-01",
"summary": "Global movement of free coding clubs for young people.",
"highlights": [
"Awarded 'Teacher of the Month'"
]
}
],
"education": [
{
"institution": "University of Oklahoma",
"area": "Information Technology",
"studyType": "Bachelor",
"startDate": "2011-06-01",
"endDate": "2014-01-01",
"gpa": "4.0",
"courses": [
"DB1101 - Basic SQL",
"CS2011 - Java Introduction"
]
}
],
"awards": [
{
"title": "Digital Compression Pioneer Award",
"date": "2014-11-01",
"awarder": "Techcrunch",
"summary": "There is no spoon."
}
],
"publications": [
{
"name": "Video compression for 3d media",
"publisher": "Hooli",
"releaseDate": "2014-10-01",
"website": "http://en.wikipedia.org/wiki/Silicon_Valley_(TV_series)",
"summary": "Innovative middle-out compression algorithm that changes the way we store data."
}
],
"skills": [
{
"name": "Web Development",
"level": "Master",
"keywords": [
"HTML",
"CSS",
"Javascript"
]
},
{
"name": "Compression",
"level": "Master",
"keywords": [
"Mpeg",
"MP4",
"GIF"
]
}
],
"languages": [
{
"language": "English",
"fluency": "Native speaker"
}
],
"interests": [
{
"name": "Wildlife",
"keywords": [
"Ferrets",
"Unicorns"
]
}
],
"references": [
{
"name": "Erlich Bachman",
"reference": "It is my pleasure to recommend Richard, his performance working as a consultant for Main St. Company proved that he will be a valuable addition to any company."
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment