Duplicate an existing item into another language and open it for editing.
348459
public function translateItem($id, $lang)
	{
		$model = $this->crud['model'];
		$this->data['entry'] = $model::find($id);
		// check if there isn't a translation already
		$existing_translation = $this->data['entry']->translation($lang);

		if ($existing_translation)
		{
			$new_entry = $existing_translation;
		}
		else
		{
			// get the info for that entry
			$new_entry_attributes = $this->data['entry']->getAttributes();
			$new_entry_attributes['translation_lang'] = $lang;
			$new_entry_attributes['translation_of'] = $id;
			$new_entry_attributes = array_except($new_entry_attributes, 'id');

			$new_entry = $model::create($new_entry_attributes);
		}

		// redirect to the edit form for that translation
		return redirect(str_replace($id, $new_entry->id, str_replace('translate/'.$lang, 'edit', \Request::url())));
	}
658312
public function duplicateUnderlyingFile()
    {
        $app = Application::getFacadeApplication();
        $importer = new Importer();
        $cf = $app->make('helper/concrete/file');
        $filesystem = $this->getFile()->getFileStorageLocationObject()->getFileSystemObject();
        $fileName = $this->getFileName();
        do {
            $prefix = $importer->generatePrefix();
            $path = $cf->prefix($prefix, $fileName);
        } while ($filesystem->has($path));
        $fileContents = $this->getFileResource()->read();
        $mimeType = Util::guessMimeType($fileName, $fileContents);
        $filesystem->write(
            $path,
            $fileContents,
            [
                'visibility' => AdapterInterface::VISIBILITY_PUBLIC,
                'mimetype' => $mimeType,
            ]
        );
        $this->updateFile($fileName, $prefix);
    }
490029
def _copy_replace(src, dst, replacements):
    """"""
    with src.open() as infile, dst.open('w') as outfile:
        outfile.write(re.sub(
            '|'.join(re.escape(k) for k in replacements),
            lambda m: str(replacements[m.group(0)]),
            infile.read()
        ))
335729
def rewrite_file_imports(item, vendored_libs):
    """"""
    text = item.read_text(encoding='utf-8')
    for lib in vendored_libs:
        text = re.sub(
            r'(\n\s*)import %s(\n\s*)' % lib,
            r'\1from pythonfinder._vendor import %s\2' % lib,
            text,
        )
        text = re.sub(
            r'(\n\s*)from %s' % lib,
            r'\1from pythonfinder._vendor.%s' % lib,
            text,
        )
    item.write_text(text, encoding='utf-8')
715374
def copy(self):
        """"""
        cliptxt = self._sel_to_text( self.selectedIndexes() )
        clipboard = QApplication.clipboard()
        clipboard.setText(cliptxt)
738959
def copy(self, target, timeout=500):
        """"""

        if self.metadata and 'encoding' in self.metadata:
            with io.open(target,'w', encoding=self.metadata['encoding']) as f:
                for line in self:
                    f.write(line)
        else:
            with io.open(target,'wb') as f:
                for line in self:
                    if sys.version < '3' and isinstance(line,unicode): #pylint: disable=undefined-variable
                        f.write(line.encode('utf-8'))
                    elif sys.version >= '3' and isinstance(line,str):
                        f.write(line.encode('utf-8'))
                    else:
                        f.write(line)
836870
def copy_and_update(dictionary, update):
    """"""
    newdict = dictionary.copy()
    newdict.update(update)
    return newdict
284225
def clone(self):
        """"""
        return Leaf(self.type, self.value,
                    (self.prefix, (self.lineno, self.column)),
                    fixers_applied=self.fixers_applied)
350079
def clone(cls, objective, model=None, **kwargs):
        
        return cls(cls._substitute_variables(objective, model=model), name=objective.name,
                   direction=objective.direction, sloppy=True, **kwargs)
419800
def copy(self):
        """"""
        other = Version(None)
        other.tokens = self.tokens[:]
        other.seps = self.seps[:]
        return other
1329000
private List<MonolingualTextValue> copyMonoLingualTextValues(Collection<MonolingualTextValue> monoLingualTextValues) {
		if (filter.excludeAllLanguages()) {
			return Collections.emptyList();
		}

		List<MonolingualTextValue> result = new ArrayList<>(monoLingualTextValues.size());
		for (MonolingualTextValue mtv : monoLingualTextValues) {
			if (filter.includeLanguage(mtv.getLanguageCode())) {
				result.add(copy(mtv));
			}
		}
		return result;
	}
886873
def deep_copy(item_original):
    """"""
    item = copy.copy(item_original)
    item._id = uuid.uuid4().hex
    if hasattr(item, '_children') and len(item._children) > 0:
        children_new = collections.OrderedDict()
        for subitem_original in item._children.values():
            subitem = deep_copy(subitem_original)
            subitem._parent = item
            children_new[subitem.get_name()] = subitem
        item._children = children_new
    return item
763500
def clone(self, substitutions, commit=True, **kwargs):
        
        return self.store.clone(substitutions, **kwargs)
1297762
def translate_item(self, item_dict):
        """"""
        if not item_dict.get('title'):
            return None
        # Skip attachments
        if item_dict.get('{wp}post_type', None) == 'attachment':
            return None
        ret_dict = {}
        # slugify post title if no slug exists
        ret_dict['slug']= item_dict.get('{wp}post_name') or re.sub(item_dict['title'],' ','-')
        ret_dict['ID']= item_dict['guid']
        ret_dict['title']= item_dict['title']
        ret_dict['description']= item_dict['description']
        ret_dict['content']= item_dict['{content}encoded']
        # fake user object
        ret_dict['author']= {'username':item_dict['{dc}creator'],
                             'first_name':'',
                             'last_name':''}
        ret_dict['terms']= item_dict.get('terms')
        ret_dict['date']= self.convert_date(
            item_dict['pubDate'],
            fallback=item_dict.get('{wp}post_date','')
        )
        return ret_dict
32840
def new_filename(original_filename, new_locale):
    """"""
    orig_file = Path(original_filename)
    new_file = orig_file.parent.parent.parent / new_locale / orig_file.parent.name / orig_file.name
    return new_file.abspath()
588732
def copy(self):
        """"""
        data = QMimeData()
        text = '\n'.join([cursor.selectedText() \
                            for cursor in self.cursors()])
        data.setText(text)
        data.setData(self.MIME_TYPE, text.encode('utf8'))
        QApplication.clipboard().setMimeData(data)
1185927
def _copyItemToClipboard(self):
        """"""
        if self._current_item is None:
            return
        dp = getattr(self._current_item, '_dp', None)
        if dp and dp.archived:
            path = dp.fullpath.replace(" ", "\\ ")
            QApplication.clipboard().setText(path, QClipboard.Clipboard)
            QApplication.clipboard().setText(path, QClipboard.Selection)