How to translate an OpenERP module? - translation

I've just built a custom OpenERP module, let's say /addons/the_meaning_of_life.
Now I want to translate it to another language.
I now I'm supposed to have an i18n folder containing a .pot and .pofiles. How do I generate these ? It would be nice to have a step-by-step guide.

Ok here what you can do is:
Install your desire lang in your db.
Once you are done with your module development, install module on test server then go to the follwing Wizard Setting(or Configuration) > Translation> Import/Export/Export Translation. Then Choose the module the_meaning_of_life and desire lang. and export it in .po format.
Save that po file then add the translation that you want in the po file. Then you can import back that po file in database or add it under your module under folder /addons/the_meaning_of_life/i18n and it is available with your module.
(only for new modules), you need to have also the "pot" file in the same i18n folder, if you don't yet have it you can generate one by repeating step 2 but without choosing any language.
This how you can make available translation for the some lang in your module but if you want use Launchpad translation service then check following url this will guide you using .pot but for that you need project on lp clearly.
Hope this will answer you, Regards

Here is a bash script that I use for this:
$ cat oerp-i18n-module
#!/bin/bash
#
# usage:
# ./oerp-i18n-module <databasename> <module name>
#
# the script will create or update PO files for en, fr, de and es. You
# will need to update the translations (and don't forget bzr add +
# commit)
dirname=$(find src -name $1 | egrep -v '(src/stable)|(src/server)')
install -d ${dirname}/i18n
for lang in en fr de es
do
python src/server/openerp-server -c config/instance_debug.ini \
--log-level=error --i18n-export=${lang}.po -l ${lang} \
-d $1 --modules=$2 > /dev/null 2>&1
if [ -f ${dirname}/i18n/${lang}.po ]
then
echo merge new translations in ${dirname}/i18n/${lang}.po
msgmerge -vU --backup=simple ${dirname}/i18n/${lang}.po ${lang}.po
rm ${lang}.po
else
echo put file in ${dirname}/i18n/${lang}.po
mv ${lang}.po ${dirname}/i18n/
fi
done
Hope this helps (you may have to edit some paths which are specific to my layout of bzr branches).

Install your desire lang in your db.
Once you are done with your module development, install module on test server then go to the follwing Wizard Setting(or Configuration) > Translation> Import/Export/Export Translation. Then Choose the module the_meaning_of_life and desire lang. and export it in .po format.
Save that po file then add the translation that you want in the po file. Then you can import back that po file in database or add it under your module under folder /addons/the_meaning_of_life/i18n and it is available with your module.
(only for new modules), you need to have also the "pot" file in the same i18n folder, if you don't yet have it you can generate one by repeating step 2 but without choosing any language. This how you can make available translation for the some lang in your module but if you want use Launchpad translation service then check following url this will guide you using .pot but for that you need project on lp clearly.

Related

Conda: how to add packages to environment from log (not yaml)?

I'm doing an internship (= yes I'm a newbie). My supervisor told me to create a conda environment. She passed me a log file containing many packages.
A quick qwant.com search shows me how to create envs via the
conda env create --file env_file.yaml
The file I was give is however NOT a yaml file it is structured like so:
# packages in environment at /home/supervisors_name/.conda/envs/pancancer:
#
# Name Version Build Channel
_libgcc_mutex 0.1 main
bedtools 2.29.2 hc088bd4_0 bioconda
blas 1.0 mkl
bzip2 1.0.8 h7b6447c_0
The file contains 41 packages = 44 lines including comments above. For simplicity I'm showing only the first 7.
Appart from adding env name (see 2. below), is there a way to use the file as it is to generate an environment with the packages?
I ran the cmd using
conda env create --file supervisors.log.txt
SpecNotFound: Environment with requirements.txt file needs a name
Where in the file should I put the name?
alright, so, it seems that they give you the output of conda list rather than the .yml file produced by conda with conda env export > myenv.yml. Therefore you have two solutions:
You ask for the proper file and then proceed to install the env with conda built-in pipeline
If you do not have any access on the proper file, you could do one of the following:
i) Parse with python into a proper .yml file and then do the conda procedure.
ii) Do a bash script, downloading the packages listed in the file she gave you.
This is how I would proceed, personally :)
Because there is no other SO post on this error, for people of the future: I got this error just because I named my file conda_environment.txt instead of conda_environment.yml. Looks like the yml extension is mandatory.

Inject runtime dependency into nix package

Adding a runtime dependency to a package through override buildInputs causes the package to rebuild. Is there a simple way to inject runtime dependencies into a package without recompiling?
So basically adding package/bin to PATH and package/lib to LD_LIBRARY_PATH
If I understand correctly that you want to tweak the environment used when a Nix-installed app is run, not the one used when it is built, then a method I know of is as follows below. By using it, you essentially create a wrapper script, which overrides the "default command". So, something similar like creating e.g. a custom ~/bin/vim script, which adds some options/env overrides to the default vim binary, which is called with a "hardcoded original path" inside the script.
One example of it in nixpkgs is how vimutils.vimWithRC overrides vim command with a custom script. For your own use, you could write more or less something like below:
with import <nixpkgs> {};
writeScriptBin "vim" ''
#!/usr/bin/env bash
export PATH=package/bin:$PATH # whatever you like; I've added what you asked for
export LD_LIBRARY_PATH=package/lib:$LD_LIBRARY_PATH
${vim}/bin/vim --my-options "$#"
'';
If you put it in my-vim.nix, you should be able to install it with:
$ nix-env -e vim # REMOVE NORMAL VIM. I think this should be done first to avoid conflict
$ nix-env -i -f my-vim.nix
And hopefully it'll work and "override" the default vim for you.
DISCLAIMER: I haven't actually tested it in this exact form, sorry. Don't have a Nix console handy at this moment, unfortunately.

Setting path in Solaris Sparc

I have one python command file, i want to set it as a PATH in Solaris Sparc so that i can easily use my command from anywhere. For example the file name is abc.py and it contains abc --version to display version of file abc. So, after opening terminal i should only give command abc --version and it should display version of abc.
The architecture (SPARC) has nothing to do with the PATH which is more a shell thing but you do not tell what shell you are using.
Anyway, if you use a bourne style shell, i.e. not csh/tcsh, and you don't mind this to affect every user account on that host, you might add the wanted path to the PATH setting in the file /etc/profile.
When abc.py is located in your homedir, you can start it with ~/abc.py.
You need to call the file abc.py with abc.py, not abc (and have a shebang line which instructs the shell where it can find python).
When you want to start the file with ./abc, you can rename the file to abc (the shebang will tell it is python, not the .py), or introduce an alias:
alias abc="~/abc.py"
Using an alias can be an alternative for adding a shebang line:
alias abc="/usr/bin/python abc.py"
When you do not want to use an alias you can make a bin dir and put abc there.
I will add the shebang for you:
mkdir ~/bin
echo "#!/usr/bin/python" > ~/bin/abc
cat abc.py >> ~/bin/abc
chmod +x ~/bin/abc
mv abc.py bin/abc.py.old
Now change your login PATH with PATH=${PATH}:$HOME/bin in your .profile or .bashrc, and login again (or source the login script).

how to set up default download location in youtube-dl [closed]

Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 months ago.
The community reviewed whether to reopen this question 3 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
how can I set default download location in youtube-dl so that everything that I download with youtube-dl goes into that default directory?
You need to use the -o switch with the Configuration file
Output on youtube-dl is handled with the --output or -o switch; pass it as an option, followed by the destination you want to save your downloads to:
youtube-dl -o "%USERPROFILE%\Desktop\%(title)s-%(id)s.%(ext)s" www.youtube.com/link/to/video
Note that -o has a dual function in that it also sets a template for how your output files will be named, using variables. In this example, it will output the title of the original downloaded video followed by the file extension, which is my personal preference. For all of the variables that can be used in a filename, have a look at the youtube-dl documentation here.
youtube-dl also allows use of a configuration file - a file that can be used to configure the switches you most frequently use so the program can pull them from there instead, saving you from having to explicitly call them each time you run it. This is what you'll need for the default download location that you're looking for. The configuration file can be used to set a default output destination so that you never have to explicitly set an output again.
To set up a configuration file for youtube-dl, assuming you have Windows:
In %APPDATA%\Roaming, create a youtube-dl folder if one doesn't already exist.
Inside that folder, create a plain text file named config.txt.
Place youtube-dl options in the file as you'd normally use them on the command line with youtube-dl, placing each one on a new line. For example, for the output switch, you'd use: -o %USERPROFILE%\Desktop. For more on the Configuration file, read the documentation on it here.
Overriding the Configuration file
Even when an option is configured in a configuration file, it can be overridden by calling it explicitly from the command line. So, if you have -o set in a configuration file to be the default location for downloads, but want to save downloads to somewhere else for a current job, simply calling -o on the command line will override the configuration file for the current run of the program only.
I find a way to directly download files in Downloads folder. I search for long hours. I copied my entire function then you can understand the context around. Here is my code it will maybe helpful for someone:
import os
def download_audio(request):
SAVE_PATH = '/'.join(os.getcwd().split('/')[:3]) + '/Downloads'
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'outtmpl':SAVE_PATH + '/%(title)s.%(ext)s',
}
link = request.GET.get('video_url')
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(["https://www.youtube.com/watch?v="+link])
Tell me if there is a problem.
According to the configuration documentation, you can configure youtube-dl with a global or user-specific configuration file:
You can configure youtube-dl by placing any supported command line option to a configuration file. On Linux and macOS, the system wide configuration file is located at /etc/youtube-dl.conf and the user wide configuration file at ~/.config/youtube-dl/config. On Windows, the user wide configuration file locations are %APPDATA%\youtube-dl\config.txt or C:\Users\<user name>\youtube-dl.conf. Note that by default configuration file may not exist so you may need to create it yourself.
On linux, this would be your user config file:
# Save all my videos to the Videos directory:
-o ~/Videos/%(title)s.%(ext)s
Depending on your needs, I think moving the file afterwards would be just as usefull:
--exec CMD Execute a command on the file after
downloading, similar to find's -exec
syntax. Example: --exec 'adb push {}
/sdcard/Music/ && rm {}'
By creating a function which will move the file
Here is the complete solution I use:
from youtube_dl import YoutubeDL
ydl_opts = {
'format': 'best',
'outtmpl': 'DIR-PATH-HERE%(title)s'+'.mp4',
'noplaylist': True,
'extract-audio': True,
}
video = "https://www.youtube.com/watch?v=SlPhMPnQ58k"
with YoutubeDL(ydl_opts) as ydl:
info_dict = ydl.extract_info(video, download=True)
video_url = info_dict.get("url", None)
video_title = info_dict.get('title', None)
video_length = info_dict.get('duration')
# print(video_title)
In command line or in the bash file use the double quotes, like this:
"%userprofile%/Desktop/DL/%(title)s-%(id)s.%(ext)s"
My bash command:
youtube-dl -c -i -f "mp4" -o "/home/Youtube_Downloads/%(title)s-%(id)s.%(ext)s" -a youtube_list
where 'youtube_list' - a raw text file with Youtube links, that goes line by line
I found there is an official comment by the authors about that specific question.
In the manual, here's what they say: (man youtube-dl):
How do I put downloads into a specific folder?
Use the -o to specify an output template, for example -o "/home/user/videos/%(title)s-%(id)s.%(ext)s". If you want this for all of your downloads, put the option into your configuration file.
That filename pattern is the default, as per the man as well:
The current default template is %(title)s-%(id)s.%(ext)s.
I agree it would be nice to have the output folder decoupled from the default template in case the default changes one day, but I'm guessing the authors must have had a reason to have it this way.
This is the EXACT ANOTHER USEFUL method to download your video into a desired DIRECTORY, and also keep the native filename of the download.
Decide where you want to create a configuration file.
Create a file, "youtube-dl.conf". You can create a youtube-dl.txt first it it's easier, but the file must be "youtube-dl.conf".
Here is a basic sample of a config file: this is where you want your downloads to go. This is all you have to put into the file. Where -o is the flag, %userprofile%/Desktop/DL/ is where I want the download to go, and %(title)s-%(id)s.%(ext)s is the command to keep the native filename.This is your config file below:
-o %userprofile%/Desktop/DL/%(title)s-%(id)s.%(ext)s
Options found here
Config here
The command paramaters: %program% -f %option% "%youtubelink%" "%MYCONFIG%" "%MYPATH%"
Batch File setup:
::Variables:
Set program="%USERPROFILE%\Desktop\YOUTUBE-DL\v20201209\youtube-dl.exe"
Set option=best
SET MYPATH="%USERPROFILE%\Desktop\YOUTUBE-DL\v20201209\config"
SET MYCONFIG="--config-location"
SET MYDLDIR="%USERPROFILE%\Desktop\DL"
SET INSTR='%%(title)s-%%(id)s.%%(ext)s'
MKDIR "%USERPROFILE%\Desktop\DL"
::Ask user for input.
Set /P youtubelink=[Past Link]:
:: For use of config file, for default download location.
%program% -f %option% "%youtubelink%" "%MYCONFIG%" "%MYPATH%"
:: There are many ways to accomplish this:
:: For Batch File, NOTE extra (%) character needed.
:: "%program%" -f "option" --merge-output-format mp4 -o "%MYDLDIR%"\%%(title)s-%%(id)s.%%(ext)s %youtubelink%
:: or this use of variable
:: "%program%" -f "option" --merge-output-format mp4 -o "%MYDLDIR%"\%INSTR% %youtubelink%
NOTE: The use of "quotes" when there are spaces in your variable options.
Final Message:
Create the config file, put it in a folder (directory) that you wish to refer to it. Go to your youtube-dl.exe file and pass the "parameters" listed above to it using your CMD or a batch file. Done. (contribution, and being kind)

Script to generate Xcode empty project

I always need some empty Xcode projects for testing purposes. (I cannot use coderunner or other stuff, I really need an Xcode project).
I tried different approaches but I didn't find a real solution:
Created a basic, empty project and created a script for copying the entire folder.
It works, but you cannot have different names for the project, this means that you have to rename the project manually after the copy.
Using the Crafter gem
It's a useful gem, but you can only configure an existing project, you cannot create a new one.
Using KZBootstrap
The same as before, it's useful for configuring the project, not for creating a new one.
Using the xcodeproj gem (http://rubygems.org/gems/xcodeproj)
The documentation is not enough for me, and I don't understand how to use it :(
Any advice?
Finally i found a solution that fits my needs.
I started with an empty, sample project (here https://dl.dropboxusercontent.com/u/792862/SamplePRJ.zip)
and i wrote a bash script to rename all the files and all the occurrences of the previous name.
The script can be improved, but it basically works
export LC_CTYPE=C
export LANG=C
OLDNAME="SamplePRJ"
NEWNAME="Sample2PRJ"
mv $OLDNAME $NEWNAME
cd $NEWNAME
mv $OLDNAME $NEWNAME
mv ${OLDNAME}Tests ${NEWNAME}Tests
mv ${OLDNAME}.xcodeproj ${NEWNAME}.xcodeproj
mv ${NEWNAME}.xcodeproj/xcshareddata/xcschemes/${OLDNAME}.xcscheme ${NEWNAME}.xcodeproj/xcshareddata/xcschemes/${NEWNAME}.xcscheme
find . -type f -print0 | xargs -0 sed -i '' "s/${OLDNAME}/${NEWNAME}/g"

Resources